【发布时间】:2019-05-21 03:15:12
【问题描述】:
我正在使用 reactivePoll 来更新我闪亮的仪表板。我第一次运行该应用程序时,它运行良好。我给刷新数据的时间间隔是 1 分钟。第 1 分钟后,数据按预期刷新。从下一分钟开始,每1分钟触发一次检查功能,但没有触发价值功能,我没有得到最新的数据。
app.R
library(shiny)
library(shinythemes)
library(shinyWidgets)
library(shinydashboard)
library(shinycssloaders)
library(RPostgreSQL)
library(pool)
library(config)
library(plotly)
library(data.table)
Sys.setenv(R_CONFIG_ACTIVE = "xyz")
config <- config::get()
pool <- dbPool(
drv = dbDriver("PostgreSQL"),
host = config$host,
dbname = config$dbname,
port = config$port,
user = config$user,
password = config$password
)
onStop(function() {
poolClose(pool)
})
get_data <- function(pool) {
abc <- dbGetQuery(pool,"SELECT * FROM tablename") #Query to pull data
return(abc)
}
abc <- get_data(pool = pool)
ui <- dashboardPage(
dashboardHeader(
title = 'Dashboard'
),
dashboardSidebar(
sidebarMenu(
menuItem("pqr", tabName = "pqrs")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = 'pqrs',
hemaTab("pqr",abc = abc)
)
)
)
)
server <- function(input, output, session) {
pollData <- reactivePoll(60000, session,
checkFunc = function() {
print("Entered Check")
Sys.time()
print(Sys.time())
},
valueFunc = function() {
print("Entered value")
get_data(pool)
}
)
order(input, output, session, data = pollData())
}
shinyApp(ui = ui, server = server)
pqrs.R
pqrs <- function(id, label = "pqr",pqrs) {
ns <- NS(id)
tabPanel('pqr',
tabsetPanel(
tabPanel('Downloads',
fluidPage(
fluidRow(
column(12,
DT::dataTableOutput("table")
)
)
)
)
)
)
}
order <- function(input, output, session, data) {
downloaddata <- reactive({
setDT(data)
})
output$table <- DT::renderDataTable( DT::datatable({
downloaddata()
})
)
}
I get the following result after running the app
"Entered Check"
[1] "2018-12-20 09:53:06 EST"
[1] "Entered Check"
[1] "2018-12-20 09:53:07 EST"
[1] "entered value"
After 1 minute the dashboard gets refreshed and I get the following
result
[1] "Entered Check"
[1] "2018-12-20 09:54:07 EST"
从下一分钟开始,仪表板不会刷新,但会触发检查功能并显示时间。
【问题讨论】:
标签: r shiny shinydashboard shiny-reactivity