plotly 图表显示 ERROR too many open devices in shiny
plotly graphs shows ERROR too many open devices in shiny
我有大约 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
)
)
)
))
什么是问题?以及如何解决?
我遇到了同样的问题。我通过在 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
})
每次刷新情节时,看起来都是闪亮的creates/opens(不确定)新图形设备。你可以通过在闪亮的应用程序中打印 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
我有大约 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
)
)
)
))
什么是问题?以及如何解决?
我遇到了同样的问题。我通过在 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
})
每次刷新情节时,看起来都是闪亮的creates/opens(不确定)新图形设备。你可以通过在闪亮的应用程序中打印 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