2017-02-11 143 views
0

我正在制作一个闪亮的应用程序,它将Google数据从Google表格文档中提取到Google Drive中。在下面的MWE中,它只是列出了表格。闪亮 - 更新Google表格

我想要应用程序呈现Google表格的当前状态,因此我添加了invalidateLater以反应性表达式从Google Drive中读取数据。

缺点是每次刷新表时也是如此,即使数据没有改变。任何想法如何处理?

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") 

回答

1

好,行为当然强迫:)但是,也许工作对你来说很好。 您可以添加以下到服务器:

global <- reactiveValues(df = "") 

observe({ 
    if(! identical(global$df,DF())) global$df = DF() 
}) 

,那么你必须在实际存在DF()这一变化只更新一个变量。 然后使output$Munt依赖于global$df

output$Munt<-renderDataTable(global$df)