【问题标题】:How to change the fonts size of sidebar in shinydashboard如何在闪亮仪表板中更改侧边栏的字体大小
【发布时间】:2018-11-27 13:55:45
【问题描述】:

我是闪亮仪表板的新手,不熟悉 CSS,谁能告诉我如何更改闪亮仪表板中侧边栏的字体大小?非常感谢,下面是我的代码。

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)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    如果你只是想改变侧边栏的字体大小,这里是代码:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      • 2016-11-11
      • 2021-12-13
      • 2018-12-24
      • 2016-12-05
      相关资源
      最近更新 更多