Hi
I'd like to display the number that was input in a color depending on the sign of the input (negative red, positive blue).
However this seems more difficult than anticipated. The problem seems to be that there's actually no number passed but a list:
"Error in tag("div", list(...)) :
(list) object cannot be coerced to type 'double'"
Also the same id cannot be called multiple times as would be necessary for the if condition and then again for the display.
I'm sure there are also other ways. I'd appreciate if you could share your solutions to this problem.
Example code:
library(shiny)
library(shinydashboard)
server <- function(input,output,session) {
output$val1<-renderText({input$testinput})
}
#Elements of the UI:
header<-dashboardHeader(title = "Coloring_Test",titleWidth = 280)
sidebar<-dashboardSidebar(width = 280,sidebarMenu(id="sidebar_tabs",
menuItem("AAA", tabName = "AAA")
))
body<-dashboardBody(title="Main",
tabItem(tabName = "Overview",h1("Overview"),
fluidPage(
box(sliderInput(inputId = "testinput",label="testinput",min=-30,max=20,value=5)),
# Code with coloring
box(title="Output",tags$p(textOutput(outputId="val1", inline=TRUE),style="color:#1E90FF"))
# ,
# Code with condition, which does not work
# box(title="Output",if(textOutput(outputId="val1")>=0){tags$p("IF",style="color:#1E90FF")}else{tags$p("ELSE",style="color:#ff5733")}) # Condition
)
)
)
ui <- dashboardPage(skin = "black", header, sidebar, body)
shinyApp(ui = ui, server = server)