簡體   English   中英

R閃亮的值框和量規無法一起使用

[英]R Shiny valueBox and gauge not working together

我的Shiny App出現問題。 我的應用程序具有一個valueBox ,在我從flexdashboard程序包引入gauge之前,它可以正常工作。

使用gauge我的valueBox不再在UI中呈現。

閱讀其他文章,我認為這是flexdashboard軟件包的問題。

任何變通辦法將不勝感激。

下面是一些可復制的代碼:

library(shiny)
library(shinydashboard)
#library(flexdashboard)


ui <-dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
  valueBoxOutput("vbox1"),
  column(6,box(plotOutput("plt1"),width=12,title="Gauge Graph",background ="green") ),

column(6,box(plotOutput("plt2"),width=12,title="Graph2",background="yellow") )
),
fluidRow( actionButton("plot","plot") )
)
)

server <- shinyServer(function(input, output, session) {
observeEvent(input$plot,{
output$plt1 <- renderPlot({
  flexdashboard::gauge(56, min = 0, max = 100, symbol = '%', label = paste("Test Label"),gaugeSectors(
    success = c(100, 6), warning = c(5,1), danger = c(0, 1), colors = c("#CC6699")
  ))

})
output$plt2 <- renderPlot({plot(runif(100),runif(100))})
})

output$vbox1 <- renderValueBox({
valueBox(
  "Gender",
  input$count,
  icon = icon("users")
 )
})
})

shinyApp(ui = ui, server = server)

您可以使用flexdashboard名稱空間,而不是采購庫。

您可以執行以下操作:

library(shiny)
library(shinydashboard)
# library(flexdashboard)


ui <-dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      valueBoxOutput("vbox1"),
      column(6,box(flexdashboard::gaugeOutput("plt1"),width=12,title="Gauge Graph",background ="green") ),

      column(6,box(plotOutput("plt2"),width=12,title="Graph2",background="yellow") )
    ),
    fluidRow( actionButton("plot","plot") )
  )
)

server <- shinyServer(function(input, output, session) {
  observeEvent(input$plot,{
    output$plt1 <- flexdashboard::renderGauge({
      flexdashboard::gauge(56, min = 0, max = 100, symbol = '%', label = paste("Test Label"),
                           flexdashboard::gaugeSectors(success = c(100, 6), warning = c(5,1), danger = c(0, 1), colors = c("#CC6699")
      ))

    })
    output$plt2 <- renderPlot({plot(runif(100),runif(100))})
  })

  output$vbox1 <- renderValueBox({
    valueBox(
      "Gender",
      input$count,
      icon = icon("users")
    )
  })
})

shinyApp(ui = ui, server = server) 

使用此代碼,應用程序如下所示: 在此處輸入圖片說明

希望能幫助到你!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM