gpt4 book ai didi

javascript - Shiny 应用程序中 `js` 中变量名称中的点

转载 作者:行者123 更新时间:2023-11-28 03:49:01 25 4
gpt4 key购买 nike

我试图重现 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) {
}
))

这不会返回下拉菜单中的彩色变量。我能看到的唯一区别是我的变量名。有限制吗?

最佳答案

我建议使用 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 .

关于javascript - Shiny 应用程序中 `js` 中变量名称中的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53869435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com