简体   繁体   English

如何在Shiny中减少sidebarPanel文本大小?

[英]How to Reduce sidebarPanel Text Size in Shiny?

How would I reduce the text size and selectInput box size in my Shiny application? 我将如何减少文字大小和selectInput在我的盒子大小Shiny应用程序?

Right now, I have four selectInput boxes and corresponding titles and they are pretty large. 现在,我有四个selectInput框和相应的标题,它们非常大。 I am looking to include up to 16 of them, but with a reduced size. 我希望包含多达16个,但尺寸减小。 I've included a sample ui.R from the Shiny tutorial. 我在Shiny教程中包含了一个示例ui.R Thanks for your help! 谢谢你的帮助!

Update: I updated the following code with the tags$style line. 更新:我使用tags$style line更新了以下代码。 This made the text smaller. 这使文本更小。 Now, I'm not sure how to make the selectInput box smaller. 现在,我不确定如何使selectInput框更小。

shinyUI(fluidPage(
  titlePanel("censusVis"),

  sidebarLayout(
    sidebarPanel(
      helpText("Create demographic maps with 
        information from the 2010 US Census."),
      tags$style(type='text/css', ".selectize-input { font-size: 10px; line-height: 10px;} .selectize-dropdown { font-size: 10px; line-height: 10px; }")
      selectInput("var", 
        label = "Choose a variable to display",
        choices = c("Percent White", "Percent Black",
          "Percent Hispanic", "Percent Asian"),
        selected = "Percent White"),

      sliderInput("range", 
        label = "Range of interest:",
        min = 0, max = 100, value = c(0, 100))
    ),

    mainPanel(
      textOutput("text1")
    )
  )
))

To reduce the font size, just add a bit of CSS to the document's header, targeting elements of class "selectize-input" and "selectize-dropdown" . 要减小字体大小,只需在文档标题中添加一些CSS,定位"selectize-input""selectize-dropdown"类的元素。 (Those affect, respectively, the font size shown in the selection bar and in its dropdown menu.) (这些分别影响选择栏和下拉菜单中显示的字体大小。)

To reduce the control's width, you can wrap it in a fluidRow() and allocate it some fraction of the 12 columns that the row contains. 要减小控件的宽度,可以将其包装在fluidRow()并将其分配给该行包含的12列中的一小部分。

Here's a fully reproducible example, which you can run by just copy and pasting into R: 这是一个完全可重现的示例,您只需将其复制并粘贴到R中即可运行:

library(shiny)

shinyApp(
    ui = fluidPage(
        tags$head(tags$style(HTML("
        .selectize-input, .selectize-dropdown {
          font-size: 75%;
        }
        "))),    
        titlePanel("censusVis"),
        sidebarLayout(
            sidebarPanel(
                helpText("Create demographic maps with
        information from the 2010 US Census."),    
                fluidRow(column(6,
                       selectInput("var",
                            label = "Choose a variable to display",
                            choices = c("Percent White", "Percent Black",
                                "Percent Hispanic", "Percent Asian"),
                            selected = "Percent White")
                )),
                sliderInput("range",
                            label = "Range of interest:",
                            min = 0, max = 100, value = c(0, 100))
                ),
            mainPanel(textOutput("text1"))
        )
    ),
    server = function(input, output) {}
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM