Изменение размера шрифта valueBoxes

Я хотел бы изменить размер шрифта значения и подзаголовок для 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)

person h.l.m    schedule 18.07.2016    source источник


Ответы (1)


Привет, вы можете изменить размер шрифта непосредственно в valueBox с помощью тега p, не переписывая функцию valueBox (если хотите, просто оберните value и subtitle аргументы в 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)
person Victorp    schedule 26.07.2016
comment
Удивительно, спасибо, один быстрый вопрос, есть ли способ изменить цвет на нестандартный, используя шестнадцатеричный код вместо синего или цвета морской волны? - person h.l.m; 26.07.2016
comment
Не с shinydashboard, можно с CSS, но это некрасиво: .small-box { background-color: #FFFF00 !important; color: #000000 !important; } - person Victorp; 26.07.2016
comment
Спасибо, я заметил одну вещь: вы не использовали valueBoxOutput и renderValueBox... это позволяет им быть динамическими... в то время как ваш метод достаточно фиксирован... можете ли вы порекомендовать корректировку? - person h.l.m; 26.07.2016
comment
Есть ли способ изменить размер шрифта для всех значений в моем приложении? Я попробовал 'tags$p(tags$style(HTML(.small-box {font-size: 10px})))' в DashboardBody(), но не работает - person Lefkios Paikousis; 14.09.2020