Hello snt,
Check out renderUi and uiOutput functions it may help you with this issue. Also this link about how to Build a dynamic UI that reacts to user input may be useful too.
Here is a solution with this approach:
library(shiny)
library(shinyWidgets)
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
sidebar <- dashboardSidebar(sidebarMenu(
id = "tab",
menuItem("1", tabName = "1"),
menuItem("2", tabName = "2"),
menuItem("3", tabName = "3"),
menuItem("4", tabName = "4")
))
body <- ## Body content
dashboardBody(
box(width = 12,
fluidRow(
column(uiOutput("dynamicPicker"), width = 3)
)
)
)
ui <- dashboardPage(
dashboardHeader(title = "Scorecard"),
sidebar,
body
)
# Define the server code
server <- function(input, output, session) {
output$dynamicPicker <- renderUI({
if (input$tab == "1") {
uiOutput <- pickerInput(inputId = "metric", label = h4("Metric Name"),
choices = c("alpha","beta"), width = "100%")
} else if (input$tab == "2") {
uiOutput <- pickerInput(inputId = "metric", label = h4("Metric Name"),
choices = c("alpha","orange"), width = "100%")
}else {
uiOutput <- pickerInput(inputId = "metric", label = h4("Metric Name"),
choices = c("foo","zoo", "boo"), width = "100%")
}
return(uiOutput)
})
}
shinyApp(ui = ui, server = server)
Created on 2018-08-08 by the reprex package (v0.2.0).
Hope it helps!