如何使用Shinydashboard()?如何使用、Shinydashboard

2023-09-04 02:21:17 作者:空城旧梦丶旧少年

我希望能够选择将由useShinydashboard()命令修改的valueBox,而不是以下示例中的全部

library(shiny)
library(shinydashboard)
library(shinyWidgets)

ui <- fluidPage(
    tags$h2("Classic shiny"),
    
    setBackgroundColor(color = "ghostwhite"),
    useShinydashboard(),

    fluidRow(
        
        valueBox(
            tagList("60", tags$sup(style="font-size: 20px", "%")),
            "Approval Rating", icon = icon("line-chart"), color = "green"
        ),
        valueBox(
            htmlOutput("progress"), "Progress", icon = icon("users"), color = "purple"
        )))

server <- function(input, output, session) {
    
    output$orderNum <- renderText({
        prettyNum(input$orders, big.mark=",")
    })
    
    output$progress <- renderUI({
        tagList(input$progress, tags$sup(style="font-size: 20px", "%"))
    })
    
}

shinyApp(ui, server)

#编辑

基于shinydashboard搭建你的仪表板 二

添加如何useShinydashboard()

如果没有useShinydashboard(),则如下所示

我想要第一个选项,因此必须添加useShinydashboard()。 第一个valueBox

生成
valueBox(value=div(paste(1.51,"(1 óbito a cada 66 casos)"),style="font-size:25px;"),
               subtitle = tags$div(HTML('<b style = "padding-left:10px;font-size:16px">LETALIDADE</b>')),
               width=12,
               #icon = icon("skull", lib = "font-awesome"),
               color = "black")

问题在于useShinydashboard()命令在全局范围内更改。下图是没有useShinydashboard()的情况(这就是我想要的)

useShinydashboard()命令如下

推荐答案

或许您可以在ui上使用此函数。

myvalueBox <- function (value, subtitle, icon = NULL, color = "white", 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", h3(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)
}

然后将程序中的valueBox()替换为myvalueBox

 
精彩推荐
图片推荐