Naming tabPanel elements

In order to allow testing for which tab is currently selected, we're going to have to first give the tabs of the tabbed output names. This is done as follows (with the new code in bold):

tabsetPanel(id = "theTabs",
tabPanel("Summary", textOutput("summary"),
value = "summary"),
tabPanel("Trend", plotOutput("trend"),
value = "trend"),
tabPanel("Map", leafletOutput("map"),
p("Map data is from the most recent year in the selected range"),
value = "map")
)

As you can see, the whole panel is given an ID (theTabs) and then each tabPanel is also given a name (summary, trend, map). They are referred to in the server.R file very simply as input$theTabs.

Finally, we can make our changes to ui.R to remove parts of the UI based on tab selection:

conditionalPanel(
condition = "input.theTabs == 'trend'",
checkboxInput("linear", label = "Add trend line?",
value = FALSE)
),

As you can see, the condition appears very R/Shiny-like, except with the . operator familiar to JavaScript users in place of $. This is a very simple but powerful way of making sure that your UI is not cluttered with irrelevant material.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset