Reputation: 514
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")
Upvotes: 1
Views: 827
Reputation: 17689
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)
Upvotes: 3