pickerInput font or background color

荒凉一梦 提交于 2020-04-16 02:40:50

问题


I am using pickerInput in my shiny dashboard, which is fine except for one issue: The background color and font color are too similar, making the filter choices difficult to read.

Is there any way to change either the background or font color? I'd like to continue to use pickerInput if possible, but if there's a method with selectInput or anything else that'd be fine.

Sample of one of my pickerinputs that produces the result in the screenshot:

output$typeOutput80 <- renderUI({
  Commodity.Name <- as.vector( unique(DF2()$Commodity.Name) )
  pickerInput("typeOutput80", "Commodity:", 
     choices=Commodity.Name, Commodity.Name [1:10000], multiple=TRUE, 
     options = list(`actions-box` = TRUE, `live-search` = TRUE, 
                    `selected-text-format`= "static", title = "Commodity List")
  )
})`

回答1:


This is a bit of a hacky solution, but it may work for you, or at least send you down the right path.

You can use the choicesOpt argument of pickerInput to describe formatting for individual options within the dropdown menu. Specifying the colour, background, or weight there will change the relevant elements to whatever you choose. The trick is that the arguments apply to only the first choice, so you need to replicate the style argument for as many choices as you have. I've done this with rep() and I've just stuck a value there (10) to match choices, but you will likely want to define that value programmatically based on wherever your Commodity List data is from.

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput("id", "Formatting changes", multiple=T, choices = sample(LETTERS, size = 10), 
              options = list(`actions-box` = TRUE, `live-search` = TRUE, 
                         `selected-text-format`= "static", title = "Commodity List"),
              choicesOpt = list(
                style = rep(("color: black; background: lightgrey; font-weight: bold;"),10)))
)

server <- function(input, output){}

shinyApp(ui, server)


来源:https://stackoverflow.com/questions/54081254/pickerinput-font-or-background-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!