Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Shiny icon smaller in Valuebox

Tags:

r

shiny

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"
    )

enter image description here

like image 284
Makiyo Avatar asked Oct 01 '17 15:10

Makiyo


2 Answers

1. Changing the size of all icons

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){}
)

enter image description here

2. Changing the size of a single element

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){}
)

enter image description here

like image 197
GoGonzo Avatar answered Oct 30 '22 07:10

GoGonzo


Try setting subtitle = HTML("&nbsp;") instead of NULL. This will enter the invisible HTML character non-breaking space which will add the vertical space you need.

like image 28
Samuel Avatar answered Oct 30 '22 07:10

Samuel