jeudi 4 août 2016

R Shiny: Use same checkBoxGroup twice

the code below shows a UI with two tabs with each containing the same checkbox panel. I would like one panel to update if the other is updated and vice versa. In the server the observe function is used but for some reason it only updates the checkBoxGroup on tab2 if tab1 is changed but not the other way around. Does anyone have ideas on how to solve this?

   library(shiny)

    ui <- shinyUI(
      navbarPage("tabs",           
                 tabPanel("tab1", 
                          fluidPage(
                            sidebarPanel(
                              checkboxGroupInput("variable", "variable:",list("1" = "1","2" = "2","3" = "3","4" = "4","5" = "5"), selected = list("1"="1"))
                            )
                          )),
                 tabPanel("tab2", 
                          fluidPage( 
                            sidebarPanel(
                              checkboxGroupInput("variable", "variable:",list("1" = "1","2" = "2","3" = "3","4" = "4","5" = "5"), selected = list("1"="1"))
                            )
                          )
                 )
      )
    )

    server <- function(input, output, session) {
      observe({
        updateCheckboxGroupInput("variable","variable:",list("1" = "1","2" = "2","3" = "3","4" = "4","5" = "5"),selected=input$variable)
      })

    }

    shinyApp(ui = ui, server = server)




Aucun commentaire:

Enregistrer un commentaire