我的 Shiny 图标对于我的 valuebox 来说太大了,我知道如何通过添加“fa-3x”来将它变大,但是有人可以告诉我如何将它变小吗?谢谢!
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"
)
最佳答案
1.改变所有图标的大小
Shiny icon()
在这种情况下使用 font-awesome。根据 this answer , 可以通过指定 font-size
来减小图标的大小在 CSS 中。要在 Shiny 中实现这一点,只需在 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){}
)
2.改变单个元素的大小
如果想要更改一个元素的大小而不是所有具有相同类的元素(在这种情况下为
.fa
),请使用 tags$i(class = "fas fa-thumbs-down", style="font-size: 12px")
而不是 icon()
.可以找到合适的类(class)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){}
)
关于r - 使 Valuebox 中的 Shiny 图标变小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46513757/