2017-10-13 76 views
0

我遇到了我的Shiny應用程序問題。在我從flexdashboard軟件包中引入gauge之前,我的應用程序的valueBox工作正常。R Shiny valueBox和計量器不能一起工作

隨着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) 
+0

https://www.rdocumentation.org/packages/flexdashboard/versions/0.4/topics/gauge-shiny –

回答

1

你可以使用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) 

使用此代碼的應用程序是這樣的:enter image description here

希望它能幫助!