【问题标题】:Changing the font size of valueBoxes更改 valueBoxes 的字体大小
【发布时间】:2016-07-18 16:26:27
【问题描述】:

我想更改valueBoxes 的值和字幕的字体大小。

以下是我的尝试,但如果有任何关于如何以类似于默认外观的方式更改它的建议,我将不胜感激。以下是我的可重现示例。

require(shinydashboard)

valueBox2 <- function (value,header_val=4, subtitle, icon = NULL, color = "aqua", width = 4, 
                       href = NULL) {
  shinydashboard:::validateColor(color)
  if (!is.null(icon)) 
    shinydashboard:::tagAssert(icon, type = "i")
  boxContent <- div(class = paste0("small-box bg-", color), 
                    div(class = "inner", eval(parse(text=paste0('h',header_val,'(',shQuote(value),')'))), p(subtitle)), if (!is.null(icon)) 
                      div(class = "icon-large", icon))
  if (!is.null(href)) 
    boxContent <- a(href = href, boxContent)
  div(class = if (!is.null(width)) 
    paste0("col-sm-", width), boxContent)
}

ui = dashboardPage(title='hello',
  dashboardHeader(title='hello2'),
  dashboardSidebar(
    sliderInput('hval',label='header value',min=1,max=6,value=3)
  ),
  dashboardBody(
    valueBoxOutput('tmp')
  )
)

server = function(input, output) {
  output$tmp <- renderValueBox({
    valueBox2(value='90k',header_val = input$hval, subtitle='some long descritptive text',icon=icon("car"))
    })
}

shinyApp(ui=ui,server=server)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您好,您可以直接在valueBox 中使用p 标记更改字体大小,而无需重写valueBox 函数(如果您愿意,只需将valuesubtitle args 包装在tags$p 中),试试:

    library("shiny")
    library("shinydashboard")
    
    # header
    header <- dashboardHeader(title = "Changing the font size of valueBoxes", titleWidth = 450)
    
    # sidebar
    sidebar <- dashboardSidebar(disable = TRUE)
    
    # body
    body <- dashboardBody(
      valueBox(
        value = "90k",
        subtitle = "some long descritptive text",
        icon = icon("car")
      ),
      valueBox(
        value = tags$p("90k", style = "font-size: 150%;"),
        subtitle = tags$p("some long descritptive text", style = "font-size: 150%;"),
        icon = icon("car fa-lg")
      ),
      valueBox(
        value = tags$p("90k", style = "font-size: 200%;"),
        subtitle = tags$p("some long descritptive text", style = "font-size: 200%;"),
        icon = icon("car fa-2x")
      ),
      valueBoxOutput(outputId = "mybigbox")
    )
    
    # server
    server <- function(input, output) {
      output$mybigbox <- renderValueBox({
        valueBox(
          value = tags$p("90k", style = "font-size: 300%;"),
          subtitle = tags$p("some long descritptive text", style = "font-size: 300%;"),
          icon = icon("car fa-3x")
        )
      })
    }
    shinyApp(ui = dashboardPage(header, sidebar, body), server = server)
    

    【讨论】:

    • 太棒了,谢谢,一个简单的问题,有没有办法通过使用十六进制颜色代码而不是“蓝色”或“浅绿色”来将颜色更改为非标准颜色?
    • 不能用shinydashboard,你可以用CSS,但它不漂亮:.small-box { background-color: #FFFF00 !important; color: #000000 !important; }
    • 谢谢,我注意到的一件事是您没有使用valueBoxOutputrenderValueBox ...这使它们可以是动态的...因为您的方法非常固定。 ..你能推荐一个调整吗?
    • 有没有办法可以更改我的应用程序中所有 valueBoxes 的字体大小?我在 DashboardBody() 中尝试了 'tags$p(tags$style(HTML(".small-box {font-size: 10px}")))' 但不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 2011-01-17
    • 2013-10-05
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多