首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改shinyWidgets包的pickerInput字体大小

如何更改shinyWidgets包的pickerInput字体大小
EN

Stack Overflow用户
提问于 2020-06-05 18:58:23
回答 1查看 466关注 0票数 0

在一个闪亮的应用程序中,我使用的是shinyWidgets包中的pickerInput。我希望在较大的屏幕(台式机、笔记本电脑)上使用大字体,在较小的屏幕(智能手机、iPhone)上使用较小的字体。我试过这个:

代码语言:javascript
复制
library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$style("@media (max-width: 1000px) { .pClass { font-size: 12; color: green} }
              @media (min-width: 1001px) { .pClass { font-size: 18; color: blue } }"),

  pickerInput(
    inputId    = "pInput", choices = c("a", "b", "c"), multiple = TRUE,

    options    = list(title      = span("Choose ...", class = "pClass"),
                      dropupAuto = FALSE, 
                      container  = 'body'),

    choicesOpt = list(class = rep("pClass", 3))
  )
)

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

shinyApp(ui = ui, server = server)

字体的调整应包括标题('Choose ...')和选项("a","b","c")。

不幸的是,给定的代码不起作用,标题是HTML代码,选项根本不受影响。

有谁有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-04 17:07:55

占位符的CSS选择器是.bootstrap-select > .dropdown-toggle。要为选项设置类,可以使用choicesOpt中的content选项,如下所示。

代码语言:javascript
复制
library(shiny)
library(shinyWidgets)

CSS <- "
@media (max-width: 1000px) { 
  .bootstrap-select > .dropdown-toggle[title='Choose ...'],
  .bootstrap-select > .dropdown-toggle[title='Choose ...']:hover,
  .bootstrap-select > .dropdown-toggle[title='Choose ...']:focus,
  .bootstrap-select > .dropdown-toggle[title='Choose ...']:active,
  .pClass {
    font-size: 12; 
    color: green;
  }
}
@media (min-width: 1001px) { 
  .bootstrap-select > .dropdown-toggle[title='Choose ...'],
  .bootstrap-select > .dropdown-toggle[title='Choose ...']:hover,
  .bootstrap-select > .dropdown-toggle[title='Choose ...']:focus,
  .bootstrap-select > .dropdown-toggle[title='Choose ...']:active,
  .pClass {
    font-size: 18; 
    color: blue;
  }
}"

pickerChoices <- c("a", "b", "c")

ui <- fluidPage(
  tags$head(tags$style(HTML(CSS))),

  pickerInput(
    inputId    = "pInput", choices = pickerChoices, multiple = TRUE,
    
    options    = list(title      = "Choose ...",
                      dropupAuto = FALSE, 
                      container  = 'body'),
    
    choicesOpt = list(
      content = sprintf("<span class='pClass'>%s</span>", pickerChoices)
    )
  )
  )

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

shinyApp(ui = ui, server = server)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62213770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档