I'm working with the sidebarPanel, using navbarPage.
I would like to "declare" only one widget (radioButtons in this example), then link each tab to the "main" sidebarPanel. As you can see, tab2 is not reactive to the relative radioButtons. The structure of my project is more complex, having the necessity to have the same sidebarPanel for some tabs and a specific sidebarPanel for some other tabs. This is the code I'm using:
library(shiny)
server=function(input, output) {
output$plot1 = renderPlot({plot(runif(input$rb))})
output$plot2 = renderPlot({plot(runif(input$rb))})
}
ui = shinyUI(navbarPage("Test multi page",
tabPanel("tab1",
sidebarLayout(
sidebarPanel(
radioButtons("rb","Nr of obs:",choices = c("50 obs"=50,"300 obs"=300))
),
mainPanel(plotOutput("plot1"))
)
),
tabPanel("tab2",
sidebarLayout(
sidebarPanel(
radioButtons("rb","Nr of obs:",choices = c("50 obs"=50,"300 obs"=300))
),
mainPanel(plotOutput("plot2"))
)
)
))
shinyApp(ui = ui, server = server)
runApp("app")
You cannot re-use ui-elements in the way you want. The closest you can get would be to use conditionalPanel. In the example below fixed
would be the input you want to have on multiple pages. Conditional panel will let you add ui components based on the active tab where tabid
is the id-label for your tabsetPanel. You don't have to use renderUI and uiOutput here but it will probably make things easier for you if you have a lot of tabs and ui-elements. To see an example take a look at this app and click through the tabs for the Data menu.
sidebarPanel(
uiOutput("fixed"),
conditionalPanel("input.tabid == 'tab1'", uiOutput("ui_tab1")),
....
)
mainPanel(
tabsetPanel(id = "tabid",
...
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With