如何在Shiny中分别控制label和selectInput选项文本的字体大小样式?

5

我在Shiny中有一个selectInput小部件。

希望分别控制label参数和小部件本身的输入文本(即choicesselected参数的文本)的字体大小。

初始的[没有样式]输出如下:

selectInput(inputId = "inId", label = "Different Font Size...", choices = "...From This")

这里输入图片描述

我尝试使用 div(),像这样:

div(style = "font-size: 8px", 
    selectInput(inputId = "inId", label = "Different Font Size...", choices = "...From This")

)

这将同时缩小label文本和输入文本(即来自choices的文本)。

enter image description here

  • Note: this is in contrast to using this div(style = ...) approach for textInput, which instead only impacts the label text (and not the input text).

    • In this instance, I would then use tags$style("#inId {font-size:8px;}") following the textInput function to modify the input font size separately.

      div(style = "font-size: 8px", 
          textInput(inputId = "inId", label = "Different Font Size...", value = "...From This")
      ), tags$style("#inId {font-size:14px;}")
      
然而,这并不适用于使用selectInput()的情况。
  • Designating a tag$style(...) following a div(style = ...) wrapper doesn't seem to do anything to the resulting text style.

      div(style = "font-size: 8px", 
          selectInput(inputId = "inId", label = "Different Font Size...", choices = "...From This")
      ), tags$style("#inId {font-size:14px;}")
      )
    

那么我该怎么做呢?

如何使用Shiny控制selectInput小部件中labelchoices文本的样式(特别是字体大小)?

  • 再次强调,我的目标是实现以下功能:

    enter image description here


如果有关系:我正在使用shiny_1.0.3和R版本3.4.0

1个回答

11

你可以使用div()将整个selectInput()标签本身都包装起来,然后分别设置不同的字体大小。标签的样式会覆盖外层div的样式。

shinyApp(
  ui = fluidPage(
    div(style = "font-size:20px;",
      selectInput(inputId = "inId", label = div(style = "font-size:80px", "Different Font Size..."), 
                  choices = c("...From This", "Test")
                  )
      )
  ),
  server = function(input, output) {

  }
)

我希望这能有所帮助。
谢谢


奇怪的是,这对我来说似乎很好用,除非我选择selectize = F,然后它对选项无效... 对此有什么想法吗? - Bajcz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接