如何更改 Shiny 中 pickerinput 的字体大小?

How to change the font size of a pickerinput in Shiny?

我正在尝试更改(减小)闪亮的 pickerinput 小部件的字体大小,但没有成功。我在线检查了其他解决方案,这有助于改变选择选项的大小。但我需要更改 selection/selected 栏中显示的字体大小及其下拉菜单选项。这是一段简单的代码:

library(shiny)

shinyApp(
  ui = fluidPage(
    titlePanel("censusVis"),
    sidebarLayout(
      sidebarPanel(
        helpText("Create demographic maps with
        information from the 2010 US Census."),    
        fluidRow(column(6,
                        pickerInput("var",
                                    label = "Choose a variable to display",
                                    choices = c("Percent White", "Percent Black",
                                                "Percent Hispanic", "Percent Asian"),
                                    selected = "Percent White",
                                    choicesOpt = list(
                                      style = rep_len("font-size: 75%; line-height: 1.6;", 4)
                                    ) # choices style
                        )
        ))
      ),
      mainPanel(textOutput("text1"))
    )
  ),
  server = function(input, output) {}
)

这一行:

choicesOpt = list(style = rep_len("font-size: 75%; line-height: 1.6;", 4)) # choices style

来自这个link:https://github.com/dreamRs/shinyWidgets/issues/74 缩小下拉菜单中的字体大小,但不缩小选择栏中的选定选项。 任何帮助将不胜感激。

使用 selectInput 代替 pickerInput 行得通吗?试试这个

runApp(shinyApp(
  ui = fluidPage(
    tags$style(type='text/css', ".selectize-input { font-size: 75%; line-height: 1.6;} .selectize-dropdown { font-size: 75%; line-height: 1.6; }"),
    selectInput(
      inputId = 'var',
      label = "Choose a variable to display",
      choices = c("Percent White", "Percent Black",
                  "Percent Hispanic", "Percent Asian"),
      selected = "Percent White"
    )
  ),
  server = function(input, output, session) {
  }
))

感谢@dreamRs 的 Victor P.。他帮我解决了这个困扰我很久的问题。这是解决方案:

library(shiny)
shinyApp(
  ui = fluidPage(
    tags$style(".my-class {font-size: 75%; line-height: 1.6;}"),
    
    shinyWidgets::pickerInput(
      inputId = "var",
      label = "Choose a variable to display",
      choices = c("Percent White", "Percent Black",
                  "Percent Hispanic", "Percent Asian"),
      selected = "Percent White",
      options = list(style = "my-class"),
      choicesOpt = list(
        style = rep_len("font-size: 75%; line-height: 1.6;", 4)
      ) # choices style
    )
  ),
  server = function(input, output) {}
)

我们应该给选择值的按钮添加一个class,然后我们就可以用这个class给按钮设置一些样式。 此案例已结案。