1

我正在尝试更改(减小)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 减小了下拉菜单中的字体大小,但不是选择栏中的选定选项。任何帮助将不胜感激。

在此处输入图像描述

4

2 回答 2

1

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

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

于 2021-12-10T21:18:53.730 回答
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) {
  }
))
于 2021-12-04T12:56:13.540 回答