我正在制作一个闪亮的应用程序,从谷歌驱动器中的谷歌工作表文档中获取数据。 在下面的MWE中,它只是提供表格。
我希望应用程序显示google工作表的当前状态,因此我将invalidateLater添加到读取来自Google驱动器的数据的反应式表达式中。
缺点是每次表都刷新,即使数据没有改变。 知道怎么处理吗?
MWE:
ui.R
library(shiny) library(shinydashboard) header <- dashboardHeader(title = "Title") sidebar <- dashboardSidebar( sidebarMenu( menuItem("All", tabName = "All", icon = icon("fa fa-circle") ) ) ) body <- dashboardBody( tabItems( tabItem(tabName = "All", fluidRow( box(width=12,title="Table", solidHeader = TRUE,status = "primary", dataTableOutput(outputId="Munt") #plotOutput(outputID="Munt") ) ) ) )) ui <- dashboardPage(header, sidebar,body)server.R
server<-function(input,output,session){ session$onSessionEnded(function() { stopApp() }) DF<-reactive({ invalidateLater(60000,session=session) temp<-gs_read(muntgeg) temp}) output$Munt<-renderDataTable(DF()) }global.R
library(shiny) library(knitr) library(googlesheets) muntgeg<-gs_title("RA-Munten")I'm making a shiny-app that takes data from a google sheets doc in google drive. In the MWE below, it just presents the table.
I want the app to present the current state of the google sheet, so I added invalidateLater to the reactive expression reading the data from google drive.
The downside is that the table refreshes as well every time, even if the data haven't changed. Any idea how to deal with that?
MWE:
ui.R
library(shiny) library(shinydashboard) header <- dashboardHeader(title = "Title") sidebar <- dashboardSidebar( sidebarMenu( menuItem("All", tabName = "All", icon = icon("fa fa-circle") ) ) ) body <- dashboardBody( tabItems( tabItem(tabName = "All", fluidRow( box(width=12,title="Table", solidHeader = TRUE,status = "primary", dataTableOutput(outputId="Munt") #plotOutput(outputID="Munt") ) ) ) )) ui <- dashboardPage(header, sidebar,body)server.R
server<-function(input,output,session){ session$onSessionEnded(function() { stopApp() }) DF<-reactive({ invalidateLater(60000,session=session) temp<-gs_read(muntgeg) temp}) output$Munt<-renderDataTable(DF()) }global.R
library(shiny) library(knitr) library(googlesheets) muntgeg<-gs_title("RA-Munten")最满意答案
嗯,行为当然是强迫的:)但是,也许一个解决方案对你来说很好。 您可以将以下内容添加到服务器:
global <- reactiveValues(df = "") observe({ if(! identical(global$df,DF())) global$df = DF() })那么你有一个变量只有在DF()实际发生变化时才会更新。 然后使output$Munt依赖于global$df
output$Munt<-renderDataTable(global$df)Well, the behaviour is kind of forced of course :) But, maybe a work around is fine for you. You could add the following to the server:
global <- reactiveValues(df = "") observe({ if(! identical(global$df,DF())) global$df = DF() })then you have a variable that is only updated when there is actually a change in DF(). And then make output$Munt dependent on global$df
output$Munt<-renderDataTable(global$df)更多推荐
发布评论