闪亮的自定义selectInput/selectizeInput [英] Shiny customize selectInput/selectizeInput
问题描述
我希望将Shiny select输入到:
I want my Shiny select input to:
- 没有标签
- 具有自定义的背景色:
#2f2d57
- 具有占位符
- 使用户能够输入并选择
但是,我无法使该应用程序同时遵守上述4条规则.我的代码如下:
However, I can't make the app follow the above 4 rules together. My codes are below:
数据:
table <- data.frame(col1 = c(3, 4, 8, 5, 2, 6, 7))
尝试1
问题:用户无法键入内容并从selectInput中选择
Problem: Users are unable to type-in and select from the 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
,用户可以键入内容进行选择,但背景颜色不会更改.
Problem: By deleting selectize = F
, users can type-in to select, but the background colour is not changed.
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
,但似乎仍然存在与上述相同的问题.
I was also trying selectizeInput
, but seems like it still has the same problem as above.
尝试3
问题:用户可以键入,但是背景颜色没有更改,并且selectizeInput顶部有一个我不想要的标签.
Problem: Users can to type in, but the background colour is not changed, and there's a label at the top of selectizeInput which I don't want.
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)
有人对我如何满足所有这四个规则有想法吗?预先感谢!
Does anyone have ideas on how could I be able to satisfy all the 4 rules? Thanks in advance!
推荐答案
这是一个纯粹的闪亮解决方案:
Here is a pure shiny solution:
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)
这篇关于闪亮的自定义selectInput/selectizeInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!