【问题标题】:Shiny - update googlesheetsShiny - 更新 googlesheets
【发布时间】:2017-02-11 13:37:53
【问题描述】:

我正在制作一个闪亮的应用程序,它从谷歌驱动器中的谷歌表格文档中获取数据。在下面的 MWE 中,它只显示表格。

我希望应用程序呈现 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)

服务器.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())

    }

全球.R

library(shiny)
library(knitr)
library(googlesheets)

muntgeg<-gs_title("RA-Munten")

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    嗯,这种行为当然是一种强迫行为 :) 但是,也许解决方法对你来说很好。 您可以将以下内容添加到服务器:

    global <- reactiveValues(df = "")
    
    observe({
       if(! identical(global$df,DF())) global$df = DF()
    })
    

    那么你有一个变量,只有在DF() 实际发生变化时才会更新。 然后让output$Munt依赖global$df

    output$Munt<-renderDataTable(global$df)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 2014-03-23
      • 1970-01-01
      • 2018-04-28
      • 2019-11-03
      • 2020-12-21
      • 2019-02-12
      相关资源
      最近更新 更多