2016-07-14 193 views
3

我有大約10個從ggplot轉換的密謀圖在我的閃亮的應用程序,這是每10秒刷新一次。 Plotly可以很好地進行刷新,但是會顯示錯誤太多的開放設備。密謀圖顯示錯誤太多閃亮的開放設備

我的代碼如下(短路到只顯示一個曲線圖):

server.R

pullData是函數,從數據庫中提取數據。

library(lubridate) 
library(shinyjs) 
library(ggplot2) 
library(plotly) 
server <- function(input, output, session) { 


d <- reactive({ 
    invalidateLater(10000, session) 
    pullData() %>% filter(!is.na(time)) 
}) 

output$Run <- renderPlotly({ 
pdf(NULL) 
ggplotly(ggplot(d(), aes(x = as.POSIXlt(time) , y = mile)) + 
    geom_point() + 
    theme_bw() + 
    xlab('Time') + 
    ylab('mile')) 
}) 

ui.R

library(shinydashboard) 
library(shiny) 
library(shinyjs) 
library(plotly) 

ui <- dashboardPage(

    dashboardHeader(title = "Analytics DashBoard") 
    ,skin = 'green' 
    ,dashboardSidebar(
     tags$head(
     tags$style(HTML(" 
         .sidebar { height: 90vh; overflow-y: auto; } 
         ") 
    ) 
    ), 
#  sidebarSearchForm(label = "Search...", "searchText", "searchButton"), 
     sidebarMenu(


     , menuItem("Real Time Graphs", tabName = "RealTimeG", icon = icon("cog")) 


    ) 

    ) 


    ,dashboardBody(
    tabItems(
    ,tabItem(
     tabName = "RealTimeG" 


     ,fluidRow(
     box(
     title = "total Run Time" 
     ,plotlyOutput("Run") 
     , width = 6 
     ) 
     ) 
    ) 
)) 

是什麼問題?以及如何解決它?

回答

3

我有同樣的問題。我使用renderPlotly函數中的dev.off()解決了這個問題。嘗試做這樣的事情:

utput$Run <- renderPlotly({ 
pdf(NULL) 
g<-ggplotly(ggplot(d(), aes(x = as.POSIXlt(time) , y = mile)) + 
geom_point() + 
theme_bw() + 
xlab('Time') + 
ylab('mile')) 
dev.off() 
g 
}) 

貌似閃亮的創建/打開(不知道),新的圖形設備的每一個情節刷新時間。呦可以通過在您的閃亮應用程序中打印dev.list()來檢查此問題。幾次刷新後你會得到這樣的東西:

RStudioGD  png  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf 
     2   3   4   5   6   7   8   9  10  11 
    pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf 
    12  13  14  15  16  17  18  19  20  21 
    pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf 
    22  23  24  25  26  27  28  29  30  31 
    pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf  pdf 
    32  33  34  35  36  37  38  39  40  41 
    pdf  pdf  pdf  pdf  pdf 
    42  43  44  45  46 
+0

謝謝你,它的工作! –