1

I am building a shinydashboard app and I want to be able to use the same object in multiple tabs. For example, in the code below I've created the radioButtons data1 and data2, both of which correspond to the Model1 and Model2 tabs, respectively. However, is there a way to create one radioButton, named data, and have it be used in both tabs? Since I want the value for this to remain the same across all tabs, it would save time and coding space to have only one instance.

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title='Title'),
  dashboardSidebar(
    sidebarMenu(
      menuItem('Models', tabName='Models',
        menuSubItem('Model1', tabName='Model1'),
        menuSubItem('Model2', tabName='Model2')
      ),
      tags$head(tags$script(HTML('$(document).ready(function() {$(".treeview-menu").css("display", "block");})')))
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName='Model1',
        h1("Model 1"),
        radioButtons('data1', 'Select Data',
          choices=list("Use Old Data"='old', "Use New Data"='new')
        ),
        verbatimTextOutput('out1')
      ),
      tabItem(tabName='Model2',
        h1("Model 2"),
        radioButtons('data2', 'Select Data',
          choices=list("Use Old Data"='old', "Use New Data"='new')
        ),
        verbatimTextOutput('out2')
      )
    )
  )
)

server <- function(input, output, session) {
  output$out1 <- renderPrint(input$data1)
  output$out2 <- renderPrint(input$data2)
}

shinyApp(ui, server)
Gaurav Bansal
  • 5,221
  • 14
  • 45
  • 91
  • 2
    http://stackoverflow.com/questions/21863898/r-shiny-multiple-use-in-ui-of-same-renderui-in-server – Sumedh Aug 09 '16 at 17:36

0 Answers0