Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with using rintrojs inside shiny modules #15

Closed
rpodcast opened this issue Oct 21, 2016 · 3 comments
Closed

Problems with using rintrojs inside shiny modules #15

rpodcast opened this issue Oct 21, 2016 · 3 comments

Comments

@rpodcast
Copy link

@rpodcast rpodcast commented Oct 21, 2016

I'm helping to develop a complex shiny application that makes use of modules to streamline the development. We'd really like to use rintrojs as our way of providing in-app help. But it does not work correctly when included inside the UI portion of a shiny module, through it works as expected when it is only in the non-module UI portion. Below are examples of each case:

Working example

library(shiny)
library(rintrojs)
selectorUI <- function(id) {
  ns <- NS(id)

    selectizeInput(inputId = ns('select'),
                   label = 'Make a choice:',
                   choices = c('Option one', 'Option two'))

}
ui <- shinyUI(fluidPage(
  introjsUI(),

  introBox(
    titlePanel("Old Faithful Geyser Data"),
    data.step = 1,
    data.intro = "this is a try" 
  ),


  selectorUI('id1'),
  conditionalPanel(condition = "input['id1-select'] == 'Option one'",
                   p('Option one is selected.'))
  ,actionButton("help", "Press for instructions")
))

server <- shinyServer(function(input, output, session) {


  observeEvent(input$help,
               introjs(session, options = list("nextLabel"="Onwards and Upwards",
                                               "prevLabel"="Did you forget something?",
                                               "skipLabel"="Don't be a quitter"),
                       events = list("oncomplete"='alert("Glad that is over")'))
  )

})

shinyApp(ui = ui, server = server)

Non-working example

Error is ERROR: could not find function "ns" when running the ui portion of code.

library(shiny)
library(rintrojs)
selectorUI <- function(id) {
  ns <- NS(id)
  introBox(
    selectizeInput(inputId = ns('select'),
                   label = 'Make a choice:',
                   choices = c('Option one', 'Option two')),
    data.step = 2,
    data.intro = "inside of inside"
  )

}

ui <- shinyUI(fluidPage(
  introjsUI(),

  introBox(
    titlePanel("Old Faithful Geyser Data"),
    data.step = 1,
    data.intro = "this is a try" 
  ),

  selectorUI('id1'),
  conditionalPanel(condition = "input['id1-select'] == 'Option one'",
                   p('Option one is selected.'))
  ,actionButton("help", "Press for instructions")
))

server <- shinyServer(function(input, output, session) {


  observeEvent(input$help,
               introjs(session, options = list("nextLabel"="Onwards and Upwards",
                                               "prevLabel"="Did you forget something?",
                                               "skipLabel"="Don't be a quitter"),
                       events = list("oncomplete"='alert("Glad that is over")'))
  )

})

shinyApp(ui = ui, server = server)
@carlganz
Copy link
Owner

@carlganz carlganz commented Oct 21, 2016

Thanks for the report. This appears to be an issue with environments. I am working on a solution.

@carlganz carlganz closed this in 393c1b1 Oct 21, 2016
@carlganz
Copy link
Owner

@carlganz carlganz commented Oct 21, 2016

I believe the problem is fixed now. Please download the latest version from github devtools::install_github("carlganz/rintrojs"), and let me know if you find any problems.

Your feedback is greatly appreciated. Thanks again for reporting the issue.

@rpodcast
Copy link
Author

@rpodcast rpodcast commented Oct 25, 2016

Sorry for replying back late but the fix worked flawlessly for our apps. Thanks so much for your quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.