首页 > 解决方案 > 闪亮:无法向我的值框添加颜色、图标或字幕

问题描述

我使用我构建了我的第一个仪表板,shiny并且我想添加一些值框,但是当我这样做时,值框出现时没有颜色、字幕或图标。 在此处输入图像描述

我无法弄清楚错误是什么。请提前帮助和感谢。

这是我写的代码:

library(shiny)
library(shinydashboard)
library(flexdashboard)
library(readxl)
Base_Ferias <- read_excel("C:/Users/tomas/Desktop/R/Apps/Seguimiento_ferias/Base_Avance_Ferias.xlsx")
Base_Ferias$T_respuesta <- as.numeric(Base_Ferias$T_respuesta)



ui <-dashboardPage(skin = "red",
                   dashboardHeader(title = "My Dashboard", titleWidth = 450),
                   dashboardSidebar(selectInput("actividad", "Select", 
                                                choices = Base_Ferias$Actividad)),
                   dashboardBody(
                     box(flexdashboard::gaugeOutput("chart"),width=200,
                                  title="Percentage"),
                     box(valueBoxOutput("value1"), height = "100px", width = 3)

                     )
                   )



server <- shinyServer(function(input, output, session) {

  output$chart <- flexdashboard::renderGauge({
    x <- Base_Ferias[Base_Ferias$Actividad==input$actividad,]
    y <- x$T_respuesta
    gauge(y, min = 0, max = 100, symbol = '%')
    })

  output$value1 <- renderValueBox({
    valueBox(
      paste0(25,"%"), "subtitle",icon("stats",lib='glyphicon'),
             color = "purple")
  })
})

shinyApp(ui = ui, server = server)

标签: rshinydashboardshinydashboard

解决方案


从 .附加flexdashboard具有相同名称的最后一个掩码函数shinydashboard。使用valueBoxfromshinydashboard代替:

library(shiny)
library(shinydashboard)
#> 
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#> 
#>     box

ui <-dashboardPage(skin = "red",
                   dashboardHeader(title = "My Dashboard", titleWidth = 450),
                   dashboardSidebar(selectInput("actividad", "Select", 
                                                choices = c("one", "two"))),
                   dashboardBody(
                     box(flexdashboard::gaugeOutput("chart"),width=200,
                         title="Percentage"),
                     box(valueBoxOutput(outputId = "value1"))

                   )
)



server <- shinyServer(function(input, output, session) {

  output$chart <- flexdashboard::renderGauge({
    x <- 1
    y <- 10
    flexdashboard::gauge(y, min = 0, max = 100, symbol = '%')
  })

  output$value1 <- renderValueBox({
    valueBox(
      paste0(25,"%"), "subtitle",icon("stats",lib='glyphicon'),
      color = "purple")
    })
})

shinyApp(ui = ui, server = server)
#> 
#> Listening on http://127.0.0.1:5809

reprex 包(v0.3.0)于 2020 年 3 月 4 日创建


推荐阅读