如何在selectInput
应用程序中缩小文字大小和Shiny
框大小?
现在,我有四个selectInput
框和相应的标题,它们非常大。我希望包含多达16个,但尺寸减小。我已经在ui.R
教程中添加了一个示例Shiny
。谢谢你的帮助!
更新:我使用tags$style
行更新了以下代码。这使文本更小。现在,我不确定如何使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")
)
)
))
答案 0 :(得分:4)
要缩小字体大小,只需在文档标题中添加一些CSS,定位类"selectize-input"
和"selectize-dropdown"
的元素。 (它们分别影响选择栏和下拉菜单中显示的字体大小。)
要减小控件的宽度,可以将其包装在fluidRow()
中,并将其分配给该行包含的12列中的一小部分。
这是一个完全可重现的示例,只需复制并粘贴到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) {}
)