如何更改ShinyDashboard中侧栏的字体大小 [英] How to change the fonts size of sidebar in shinydashboard
本文介绍了如何更改ShinyDashboard中侧栏的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚接触闪亮仪表板,也不熟悉css,有谁能告诉我如何在shinydashboard中更改侧边栏的字体大小?非常感谢,以下是我的代码。
library('shinydashboard')
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = 'Test'),
dashboardSidebar(
sidebarMenu(
menuItem('Tab1', tabName = '1', icon = icon('dashboard')),
menuItem('Tab2', tabName = '2', icon = icon('th'))
)),
dashboardBody(tabItems(
#First tab content
tabItem(tabName = '1',
fluidRow(
box(plotOutput('plot1', height = 250)),
box(tilte = 'Controls',
sliderInput('slider', 'Number of obs', 1, 100, 50))
)),
#Second tab content
tabItem(tabName = '2',
h2('Some text here'))
))
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
推荐答案
如果您只想更改侧边栏的字体大小,代码如下:
library('shinydashboard')
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = 'Test'),
dashboardSidebar(
sidebarMenu(
menuItem('Tab1', tabName = '1', icon = icon('dashboard')),
menuItem('Tab2', tabName = '2', icon = icon('th'))
)),
dashboardBody(
tags$head(
tags$style(HTML(".main-sidebar { font-size: 20px; }")) #change the font size to 20
),
tabItems(
#First tab content
tabItem(tabName = '1',
fluidRow(
box(plotOutput('plot1', height = 250)),
box(tilte = 'Controls',
sliderInput('slider', 'Number of obs', 1, 100, 50))
)),
#Second tab content
tabItem(tabName = '2',
h2('Some text here'))
))
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
但是,如果您想在css中做更多更改,我建议您创建一个css文件,并使用以下代码在您闪亮的应用程序中调用它:tags$head(includeCSS(path =www/style.css"))
。
您可以在此处找到更多详细信息和教程:https://shiny.rstudio.com/articles/css.html
这篇关于如何更改ShinyDashboard中侧栏的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文