aoles / shinyURL

:link: Save and restore the state of Shiny app's widgets by encoding them in an URL query string
81 stars 21 forks source link

Shiny Module UI elements #8

Open davesteps opened 8 years ago

davesteps commented 8 years ago

Hi, Great work on the package, it is really useful.

I have an app which is using shiny modules to generate a load of selectizeInput elements. The normal UI elements are captured and restored by the URL no problem, but the inputs which are modules do not seem to be. I don't know if this is possible for the future?

http://shiny.rstudio.com/articles/modules.html

aoles commented 8 years ago

Hi David, thank you for your inquiry! I started developing the package before shiny modules were available, and the current implementation doesn't support them yet. I will look into possibilities of enabling it and keep you updated on the progress.

Cheers, Andrzej

davesteps commented 8 years ago

Thats great, thanks Andrzej. To clarify, the module UI element are being included in the generated URL e.g.

Size-filter=&Vintage-filter=&FoF-filter=&

But they are not restored when loading the URL.

Best, David.

davesteps commented 8 years ago

Sorry, I was mistaken. The server logic in my app was just resetting the contents of the UI elements! I have tried it on a basic example and it will restore the state of modularized inputs (at least selectizeInput).

I am however getting the same as #5 where multiple=T but only 1 item selected.

Many thanks!

aoles commented 8 years ago

Thanks for the update! I've tried to reproduce the issue described in https://github.com/aoles/shinyURL/issues/5 but never succeed. The "Multiple select" widget in the example distributed with the package

runApp('~/Projects/shinyURL/inst/examples/widgets')

seems to work for me regardless the choices I make.

Could you maybe provide a MWE demonstrating the problem? This would be very helpful. Thanks!

davesteps commented 8 years ago

This is what I was using:

library(shinyURL)
library(shiny)

filterModuleInput <- function(id){
  ns <- NS(id)
  selectizeInput(ns('filter'),label = id,choices = c('a','b','c'),multiple=T)
}

shinyApp(
  ui = fluidPage(
    titlePanel("Hello Shiny!"),
    sidebarLayout(
      sidebarPanel(
        filterModuleInput('F1'),
        filterModuleInput('F2'),
        filterModuleInput('F3'),
        sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
        shinyURL.ui()
      ),
      mainPanel(
        plotOutput("plot")
      )
    )
  ),
  server = function(input, output, session) {
    shinyURL.server(session)
    output$plot <- renderPlot({
      x <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
  }
)
aoles commented 8 years ago

Great, thanks David! I could reproduce the described behaviour and I can confirm that there is a problem with restoring single-valued inputs in selectizeInputs. I will look into this within the next few days.

Cheers, Andrzej

aoles commented 8 years ago

Hi David, thanks again for reporting the issue and for providing a reproducible example illustrating it. With the help of your detailed report I was able to identify the problem. The bug was occurring only when the selectInput had no initial value set. It turned out that also uninitialized checkbox groups were affected by it. I've fixed this in the recent update.

Please let me know in case there are any remaining issues with using shinyURL in your app.

Cheers, Andrzej

davesteps commented 8 years ago

Nice one Andrzej, good to kill two birds with one stone! Thanks for the package 👍