juba / shinyglide

Glide.js component for Shiny apps
https://juba.github.io/shinyglide/
91 stars 8 forks source link

Does next_condition support ns() within shiny modules #24

Closed latlio closed 3 years ago

latlio commented 3 years ago

Modularizing your minimal example that I found here

The next button remains disabled even though the conditional is fulfilled. In conditionalPanel, there is an explicit ns argument included. Is there support for this within shinyglide?

test_mod_ui <- function(id) {
  ns <- NS(id)
  numericInput(ns("n"), "n :", value = 0)

  plotOutput(ns("plot"))
}

test_mod_server <- function(input, output, session) {
  output$plot <- renderPlot({
    hist(rnorm(input$n), main = paste("n =", input$n))
  })
}

ui <- fluidPage(
  glide(
    screen(
      next_condition = "input.n > 0",

      p("Please choose a value for n :"),
      test_mod_ui("mod1")
    ),
    screen(
      p("Done."),
    )
  )
)

server <- function(input, output, session) {
  callModule(test_mod_server, "mod1")

}

shinyApp(ui, server)
juba commented 3 years ago

This is not specific to shinyglide, but for this to work you have to add the module name to your element id in your condition (and you can't use the dot notation because of the presence of an hyphen) :

next_condition = "input['mod1-n'] > 0"

See also here : https://stackoverflow.com/a/39110211