I would like to have a ui element for example a radio button on one tab of a shiny app be "the same" or linked as the ui on a different tab. There potentially be other tabs that do not share that ui element.
For example, I want when I select distance in the plot tab to have it also selected when I go to the summary tab in the code below.
library(markdown)
library(shiny)
ui <- navbarPage("Navbar!",
tabPanel("Plot", sidebarLayout(sidebarPanel(
radioButtons("yaxis1", "y-axis", c("speed"="speed", "dist"="dist"),
selected = "speed"
)),
mainPanel( plotOutput("plot") ))),
tabPanel("Summary", sidebarLayout(sidebarPanel(
radioButtons("yaxis2", "y-axis", c("speed"="speed", "dist"="dist")
)),
mainPanel(verbatimTextOutput("summary"))))
)
# Server ------------------------------------------
server <- function(input, output, session) {
output$plot <- renderPlot({ plot(cars[['speed']], cars[[input$yaxis1]]) })
output$summary <- renderPrint({ summary(cars[[input$yaxis2]]) })
}
shinyApp(ui, server)
You may run the app with:
shiny::runGist('c8d5131c4e903817316e23e98cf088f9')
The following question links the tabs, but with hyperlinks:
R shiny build links between tabs
It's also kind of the opposite of the following:
How to use the same output binding on different tab panels in shiny