R语言 如何在bslib::value_box中使图标和文本更大?

hgqdbh6s  于 2023-06-19  发布在  其他
关注(0)|答案(1)|浏览(85)

我想至少将下面bslib::value_box()中的图标和文本的大小加倍:

以下是我目前为止的代码

library(shiny)
library(bslib)

ui = page_fluid(

  titlePanel("Test App"),

  fluidRow(
      selectInput("species_richness",
                  "Select number of species",
                  choices = c(1:5)),
      selectInput("mean_c",
                  "Select mean C",
                  choices = c(1:5)),
      selectInput("fqi",
                  "Select FQI",
                  choices = c(1:5))
    ),

      #boxes with key values
      layout_column_wrap(
        width = 1/3,
        bslib::value_box(
          title = "Species Richness",
          value = htmlOutput("species_richness"),
          showcase = icon("seedling")
        ),
        bslib::value_box(
          title = "Mean C",
          value = htmlOutput("mean_c"),
          showcase = icon("pagelines")
        ),
        bslib::value_box(
          title = "Total FQI",
          value = htmlOutput("fqi"),
          showcase = icon("spa")
        )
      )
)

server = function(session, input, output) {

  output$species_richness <- renderUI({
    input$species_richness
  })
  output$mean_c <- renderUI({
    input$mean_c
  })
  output$fqi <- renderUI({
    input$fqi
  })

}

shinyApp(ui, server)

如何将图标和文本放大2 - 3倍?在我的真实代码中,值是在服务器端计算的,因此解决方案必须使用htmlOutput()。我对CSS或bslib解决方案持开放态度。

wb1gzix0

wb1gzix01#

要增加图标的大小,你可以根据这个https://shiny.posit.co/r/reference/shiny/0.14/icon.html更改font-size或update类。
icon('seedling', class = 'fa-3x')
对于文本大小,在渲染时,可以通过font-size控制文本大小。您可以用途:shiny::p(input$species_richness, style = 'font-size: 40px;')
完整示例:

library(shiny)
library(bslib)

ui = page_fluid(

    titlePanel("Test App"),
    fluidRow(
        selectInput("species_richness",
                    "Select number of species",
                    choices = c(1:5)),
        selectInput("mean_c",
                    "Select mean C",
                    choices = c(1:5)),
        selectInput("fqi",
                    "Select FQI",
                    choices = c(1:5))
    ),

    #boxes with key values
    layout_column_wrap(
        width = 1/3,
        bslib::value_box(
            title = "Species Richness",
            value = htmlOutput("species_richness"),
            showcase = icon("seedling", class = 'fa-3x')
        ),
        bslib::value_box(
            title = "Mean C",
            value = htmlOutput("mean_c"),
            showcase = icon("pagelines", class = 'fa-3x')
        ),
        bslib::value_box(
            title = "Total FQI",
            value = htmlOutput("fqi"),
            showcase = icon("spa", class = 'fa-3x')
        )
    )
)

server = function(session, input, output) {

    output$species_richness <- renderUI({
        shiny::p(input$species_richness,
                 style = "font-size: 40px;")
    })
    output$mean_c <- renderUI({
        shiny::p(input$mean_c,
                 style = "font-size: 40px;")
    })
    output$fqi <- renderUI({
        shiny::p(input$fqi,
                 style = "font-size: 40px;")
    })

}

shinyApp(ui, server)

相关问题