I have about 10 ploty graphs converted from ggplot is in my shiny app, which is refreshing every 10 seconds. Plotly works fine for few refresh, but then shows ERROR too many open devices.
My code is as follows (shorted to just show one graph):
server.R
pullData is function that pulls data from database.
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
)
)
)
))
What is issue ? and How to solve it ?