我试图从this example复制结果,但是我的变量名有问题。如果我的变量名中包含CSS/HTML/js
(点),应该在.
中做什么?
首先,我尝试了以下示例,该示例正在运行,并将显示带有标记颜色的贵重物品:
t = c("A","B","C")
appCSS <-
c("#t3 ~ .selectize-control.single .selectize-dropdown [data-value=A] {color:blue}",
"#t3 ~ .selectize-control.single .selectize-dropdown [data-value=B] {color:red}",
"#t3 ~ .selectize-control.single .selectize-dropdown [data-value=C] {color:yellow}")
appCSS = str_c(appCSS,collapse = "")
runApp(shinyApp(
ui = fluidPage(
tags$head(tags$style(HTML(appCSS))),
selectInput("t3", "Color", t)
),
server = function(input, output, session) {
}
))
现在我做同样的事情,但是将向量t
更改为TX2
:
TX2
[1] "C-2.20-BL.LK.01-A-A" "C-2.20-BL.LK.01-A-B" "C-2.20-BL.LK.01-A-C"
appCSS <-
c("#t3 ~ .selectize-control.single .selectize-dropdown [data-value=C-2.20-BL.LK.01-A-A] {color:blue}",
"#t3 ~ .selectize-control.single .selectize-dropdown [data-value=C-2.20-BL.LK.01-A-B] {color:red}",
"#t3 ~ .selectize-control.single .selectize-dropdown [data-value=C-2.20-BL.LK.01-A-C] {color:yellow}")
appCSS = str_c(appCSS,collapse = "")
runApp(shinyApp(
ui = fluidPage(
tags$head(tags$style(HTML(appCSS))),
selectInput("t3", "Color", TX2)
),
server = function(input, output, session) {
}
))
这不会在下拉菜单中返回彩色变量。我唯一能看到的就是变量名。有限制吗?
答案 0 :(得分:-1)
我建议使用shinyWidgets软件包。我允许这样做。
install.packages("shinyWidgets")
library(shinyWidgets)
ui <- fluidPage(
pickerInput(inputId = "Id068",
label = "Style individual options with HTML",
choices = c("steelblue 150%",
"right align + red", "bold",
"background color"), choicesOpt = list(style = c("color: steelblue; font-size: 150%;",
"color: firebrick; text-align: right;",
"font-weight: bold;", "background: forestgreen; color: white;")))
)
server <- function(inout, output, session){}
shinyApp(ui, server)
您会找到demo on shinyapps。