In the shiny
app below I color the box based on the value of the sliderInput()
which included inside the box()
. The issue is that the box does not initially displayed if it does not have a value.
## app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$head(
tags$style(HTML("
#mybox2Red{border-top-style: none; border-left-color: red; border-left-style: solid;}
#mybox2Green{border-top-style: none; border-left-color: green; border-left-style: solid;}
"))
),
uiOutput("box2")
)
)
server <- function(input, output) {
output$box2<-renderUI({
req(input$vr)
if(input$vr<=5){
tags$style(
type = 'text/css',
"#mybox2Red{border-top-style: none; border-left-color: red; border-left-style: solid;}"
)
box(
id="mybox2Red",
title = "title",
closable = TRUE,
width = 10,
status = "danger",
solidHeader = F,
collapsible = TRUE,
collapsed = T,
sliderInput("vr","Set value range",min = 0,max=10,value = 5)
)
}
else{
tags$style(
type = 'text/css',
"#mybox2Green{border-top-style: none; border-left-color: green; border-left-style: solid;}"
)
box(
id="mybox2Green",
title = "title",
closable = TRUE,
width = 10,
status = "danger",
solidHeader = F,
collapsible = TRUE,
collapsed = T,
sliderInput("vr","Set value range",min = 0,max=10,value = 5)
)
}
})
}
shinyApp(ui, server)