I am new to shiny dashboard and don't familiar with CSS, can anyone tell me how to change the fonts size of sidebar in shinydashboard? Many thanks, below is my code.
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)
If you just want to change the font size of the sidebar here is the code :
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)
However, if you want to do more changes in CSS I advise you to create a css file and call it in your shiny app with the following code : tags$head(includeCSS(path =www/style.css"))
.
You can find more details and tutorial here : https://shiny.rstudio.com/articles/css.html
来源:https://stackoverflow.com/questions/50914223/how-to-change-the-fonts-size-of-sidebar-in-shinydashboard