I would like to use a user input (defined in a sliderInput call) in multiple tabs.
Consider the following code from this example. I would like to display the scale defined between # [reuse] and # [/reuse] also in Tab 1, without having to copy the code (i.e. the scale that is now defined between # [reuse] and # [/reuse] should be displayed in multiple tabs but only defined once).
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
tabsetPanel(
tabPanel("Tab 1", h1("First tab") ),
tabPanel("Tab2",
sidebarLayout(
# [reuse]
sidebarPanel(width = 3,
sliderInput("bins", "# bins:", min=1, max=50, value=30)),
# [/reuse]
mainPanel(plotOutput("distPlot"))
)
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
shinyApp(ui = ui, server = server)
Does someone have pointers about how to best achieve this? Many thanks in advance!