My shiny icon is too big for my valuebox, I know how to change it bigger by adding "fa-3x", but could someone please tell me how to change it smaller? Thanks!
valueBox(
value = format(movie.avg1, digits = 3),
subtitle = NULL,
icon = if (movie.avg1 >= 3) icon("thumbs-up") else icon("thumbs-down"),
color = if (movie.avg1 >= 3) "aqua" else "red"
)
Shiny icon()
uses font-awesome in this case. According to this answer, decreasing size of icon can be done specifying font-size
in css. To implement this in shiny just add this line in UI Body tags$head( tags$style(HTML(".fa{font-size: 12px;}")))
library("shiny")
library("shinydashboard")
# header
header <- dashboardHeader(
title = "Changing the font size of valueBoxes",
titleWidth = 450
)
# sidebar
sidebar <- dashboardSidebar(disable = TRUE)
# body
body <- dashboardBody(
tags$head(
tags$style(HTML(".fa{font-size: 12px;}"))
),
valueBox(
value = "3.94",
subtitle = NULL,
icon = icon("thumbs-up")
)
)
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output){}
)
If one wants to change size of one element instead of all elements with the same class (.fa
in this case), use tags$i(class = "fas fa-thumbs-down", style="font-size: 12px")
instead of icon()
. Where appropriate class can be found in font awesome docs.
library("shiny")
library("shinydashboard")
header <- dashboardHeader(
title = "Changing the font size of valueBoxes",
titleWidth = 450
)
sidebar <- dashboardSidebar(disable = TRUE)
body <- dashboardBody(
valueBox(
value = "3.94",
subtitle = NULL,
icon = tags$i(class = "fas fa-thumbs-down", style="font-size: 12px")
),
valueBox(
value = "5.00",
subtitle = NULL,
icon = tags$i(class = "fas fa-thumbs-up", style="font-size: 24px; color: white")
)
)
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output){}
)
Try setting subtitle = HTML(" ")
instead of NULL
. This will enter the invisible HTML character non-breaking space which will add the vertical space you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With