gpt4 book ai didi

javascript - Shiny 的自定义 selectInput/selectizeInput

转载 作者:搜寻专家 更新时间:2023-10-31 22:53:29 24 4
gpt4 key购买 nike

我希望我的 Shiny 选择输入:

  1. 没有标签
  2. 自定义背景颜色:#2f2d57
  3. 有占位符
  4. 让用户能够输入和选择

但是,我无法让应用同时遵循以上 4 条规则。我的代码如下:

数据:

table <- data.frame(col1 = c(3, 4, 8, 5, 2, 6, 7))

尝试 1

问题:用户无法在selectInput中输入和选择

ui <- fluidPage(
uiOutput("container")
)
server <- function(input, output) {

output$container <- renderUI({
fluidRow(
tags$style("#three_code_zip_selector {color: #ffffff; background-color: #2f2d57;}"),
selectInput('three_code_zip_selector', NULL, choices = c("Please Select Desired Number" = "", table$col1), selectize = F)
)
})
}

shinyApp(ui = ui, server = server)

尝试 2

问题:通过删除selectize = F,用户可以输入选择,但是背景颜色没有改变。

ui <- fluidPage(
uiOutput("container")
)
server <- function(input, output) {

output$container <- renderUI({
fluidRow(
tags$style("#three_code_zip_selector {color: #ffffff; background-color: #2f2d57;}"),
selectInput('three_code_zip_selector', NULL, choices = c("Please Select Desired Number" = "", table$col1))
)
})
}

shinyApp(ui = ui, server = server)

我也尝试过 selectizeInput,但似乎仍然存在与上述相同的问题。

尝试 3

问题:用户可以输入,但背景颜色没有改变,并且在 selectizeInput 的顶部有一个我不想要的标签。

ui <- fluidPage(
uiOutput("container")
)
server <- function(input, output) {

output$container <- renderUI({
fluidRow(
tags$style(".selectize-dropdown-content .active {background: #2f2d57; !important;color: #ffffff; !important;}"),
selectizeInput('three_code_zip_selector', "s", choices = c("Please Select Desired Number" = "", table$col1))
)
})
}

shinyApp(ui = ui, server = server)

有人知道我怎样才能满足所有 4 条规则吗?提前致谢!

最佳答案

这是一个纯粹 Shiny 的解决方案:

library(shiny)

table <- data.frame(col1 = c(3, 4, 8, 5, 2, 6, 7))

ui <- fluidPage(
tags$head(tags$style(HTML('
#three_code_zip_selector+ div>.selectize-dropdown{background: #2f2d57; color: #ffffff;}
#three_code_zip_selector+ div>.selectize-input{background: #2f2d57; color: #ffffff;}
'))),
selectizeInput(inputId = 'three_code_zip_selector', label = NULL, choices = table$col1, selected = NULL, multiple = TRUE, options = list('plugins' = list('remove_button'), placeholder = "Please Select Desired Number", 'create' = TRUE, 'persist' = TRUE)))


server <- function(input, output, session){}
shinyApp(ui = ui, server = server)

关于javascript - Shiny 的自定义 selectInput/selectizeInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52824678/

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