I am trying to work on a shiny app which can be easily configured. So for example I have an app with 5 tabs 10 tables and 10 charts. I want to use the same code base to publish another app with just 2 table 3 tables and 3 charts. The idea being the first view is for the analyst and the second view is for high level members. Can this be achieved using some kind of configuration method so we dont have to maintain two different code base. Thank you
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
1 Like
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.