Not sure how to handle the dynamic color from the server at the time of generating the text.
The simple example below throws an error on text2. I'm looking for an alternative to solve the problem to change the style attribute based on a certain condition.
Any suggestions?
library(shiny)
ui <- fluidPage(
br(),
textOutput("text1"),
br(),
textOutput("text2")
)
server <- function(input, output, session) {
value <- 80
# plain text
output$text1 <- renderText(paste0(value, " percent"))
# dynamic html text based on the condition - not working
output$text2 <- renderText(
ifelse(
value > 50,
div(style="color: green;", paste0(value, " percent")),
div(style="color: red;", paste0(value, " percent"))
)
)
}
shinyApp(ui, server)