0

我正在尝试在 ShinyDashBoard 中绘制一个仪表图,但我看到了两个问题。

1)仪表图不渲染

2) 它以某种方式破坏了仪表板中的 ValueBox。

以下是复制此问题的代码。

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)

还使用库生成的绘图plotly:-( 非常感谢任何有关解决此问题的帮助。在此先感谢。

4

3 回答 3

1

我遇到了同样的问题!

这是一个 UI 问题——在调用服务器输出时查看您的代码。你会想要使用flexdashboard::gaugeOutput("plt1")而不是plotlyOutput. 那应该可以解决问题。

参考:https : //cran.r-project.org/web/packages/flexdashboard/flexdashboard.pdf(即只是flexdashboard包页面)。

于 2016-08-08T16:11:34.110 回答
0

您应该使用 renderGauge 而不是 renderPlot。和gaugeOutput而不是plotOutput。

于 2021-09-20T09:38:33.350 回答
-1

1.在用户界面

column(6,box(gaugeOutput("plt1"),width=12,title="Gauge Graph",background ="green") )

在服务器中

output$plt1 <- renderGauge({
      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")
      ))
    })

2.

output$vbox1 <- renderValueBox({
    shinydashboard::valueBox(
      "Gender",
      input$count,
      icon = icon("users")
    )
  })
于 2016-11-04T06:04:28.420 回答