我希望 Shiny 根据矢量的大小打印出一些不同的颜色文本。我在想类似的事情:
output$some_text <- renderText({
if(length(some_vec) < 20){
paste("This is red text")
<somehow make it red>
}else{
paste("This is blue text")
<somehow make it blue>
...但后来我意识到,我是在服务器中执行此操作,而不是 UI。
而且,据我所知,我无法将这个条件逻辑移到 UI 中。
例如,这样的事情在 UI 中不起作用:
if(length(some_vec)< 20){
column(6, tags$div(
HTML(paste("This text is ", tags$span(style="color:red", "red"), sep = ""))
)}
else{
tags$div(HTML(paste("This text is ", tags$span(style="color:blue", "blue"), sep = ""))
)}
有人有什么创意吗?