【问题标题】:How to change the font size of a pickerinput in Shiny?如何在 Shiny 中更改选择器输入的字体大小?
【发布时间】:2022-01-10 07:59:05
【问题描述】:

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

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

来自此链接:https://github.com/dreamRs/shinyWidgets/issues/74 减小了下拉菜单中的字体大小,但不是选择栏中的选定选项。 任何帮助将不胜感激。

【问题讨论】:

  • 感谢@rawr 的编辑。这是我发布的第一个问题。

标签: css r shiny shinydashboard pickerinput


【解决方案1】:

使用 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) {
  }
))

【讨论】:

  • 感谢 Lovekesh Bazaria 的回答。但是,我特别需要使用pickerinput,因为它具有“全选/取消全选”等酷炫功能。我试图找到与您的解决方案类似的东西,但对于 pickerinput,却找不到任何东西。
【解决方案2】:

感谢来自@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) {}
)

我们应该为按钮添加一个具有选定值的类,然后我们可以使用该类在按钮上设置一些样式。 此案已结案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    相关资源
    最近更新 更多