I would like to setup a R Shiny web page that upon selecting a Disease and a Nation, and then clicking the addTab button, a new tab is created that contains more selection options. I have code (illustrated below) that mostly works. However when I create a new tab, the input values for the other tabs disappear. Any suggestions?
ui.R
# Global variables
nTabs <<- 1
shinyUI(
fluidPage(
fluidRow(
column(3,uiOutput("selectDisease")),
column(3,uiOutput("selectNation")),
column(3, actionButton("addTab", label = "Add Tab"),
actionButton("removeTab", label = "Remove Active Tab"))
),
mainPanel(
# …….
)
)
)
server.R
observeEvent (input$addTab, {
thisTab <- paste(input$diseaseSelected, "Tab", nTabs)
appendTab (inputId = "tabs", tabPanel(thisTab, {
sidebarLayout(
fluid = TRUE,
sidebarPanel (
width = 4,
h5 (paste("Disease:", input$diseaseSelected)),
h5 (paste("Nation:", input$nationSelected)),
renderUI (sideLayout(nTabs))
),
mainPanel(
# ....
)
)
}
))
updateTabsetPanel(session = session, inputId = "tabs", selected = thisTab )
nTabs <<- nTabs + 1
})
sideLayout <- function (tabNumber) {
# ……….
# seasonSelected
choices <- currentTabData$years
seasonList <- selectInput( paste0("seasonSelected", tabNumber), label = "Select a season",
choices = choices, selected = max(choices))
#periodSelected
choices <- sort(currentTabData$weeks[[i]], decreasing = TRUE)
periodList <- selectInput(paste0("periodSelected", tabNumber), label = "Select a week",
choices = choices, selected = max(choices))
list(seasonList, periodList)
}