library(shiny)
currentuser <- c("a","b")[2] # change between 1 and 2 to toggle
#define the menu
(menu_config <- tribble(
~user,~chart_1,~chart_2,
"a",TRUE,FALSE,
"b",FALSE,TRUE
))
ui <- fluidPage(
uiOutput("dynamic_ui")
)
server <- function(input, output, session) {
#define possible contents
output$chart_1 <- renderPlot(
plot(iris)
)
output$chart_2 <- renderPlot(
plot(cars)
)
output$dynamic_ui <- renderUI({
charts_to_have <- pivot_longer(menu_config,cols=-user) %>%
filter(user==currentuser, value) %>%
pull(name)
tagList(map(charts_to_have,
~plotOutput(.)))
})
}
shinyApp(ui, server)
try running this app twice one with
currentuser <- c("a","b")[2] # change between 1 and 2 to toggle
and another with
currentuser <- c("a","b")[1] # change between 1 and 2 to toggle
shiny has a session$user variable you can look into