Same selectInput across different tabs?

1,229 views
Skip to first unread message

bloosnail g

unread,
Sep 16, 2016, 8:37:33 PM9/16/16
to Shiny - Web Framework for R
Hello all, 

We are trying to have it so there is a selectInput() dropdown menu that is the same across all tabs. We have been trying to use updateSelectInput() and observeEvent() in server.R but we are having difficulty getting it to update. Code looks something like this:

#ui.R
navbarPage(
..
  tabPanel(
    ..
    selectInput("select1", width=3, label=h3("Select dataset"), choices = list("a" = "/path1", "b" = "/path2, "c = /path3")
    ..
  ),
  tabPanel(
    ..
    selectInput("select2", width=3, label=h3("Select dataset"), choices = list("a" = "/path1", "b" = "/path2, "c = /path3")
    ..
  )
)


#server.R
shinyServer(function(input, output, session){
  #neither input$select* updates the other 
  observeEvent(input$select1, function(){
    updateSelectInput(session, "select2", selected=input$select1)   
  })
  observeEvent(input$select2, function(){
    updateSelectInput(session, "select1", selected=input$select2)
  })

  #rest of code that uses input$select1
  ..
})


Would anyone know how to get around this? Or maybe if there is a way to not have the copy the same selectInput() code in ui.R with just different inputId? Thanks. 

Daniel

Laz C. Peterson

unread,
Sep 18, 2016, 10:43:45 AM9/18/16
to shiny-...@googlegroups.com
Hey there Daniel,

Not sure if this will give you any insight to solving your issue, but one suggestion could be to use renderUI/uiOutput to create your selectInput dynamically, and then observeEvent for any changes to either of those selectInput to save the selected value into a reactiveValues that can be read to set the value when using uiOutput.

If the reactiveValues item for that input is NULL, then it just doesn't create any selected value.  Of course, if the user had selected a value, when uiOutput goes to put together the selectInput on any tabPanel, it will pre-set that previously selected value.

We have a couple things like this in our apps, a little bit different than your intended function though.

Just a thought ... Hope it helps.

~Laz
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/4faca540-03d0-49f6-8d85-480f2fa4701d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 
Reply all
Reply to author
Forward
0 new messages