I am reading in real-time data from two urls into Shiny and display the last most updated 8 records. However, the data are not the most updated in Shiny,
i.e. displaying previous days' records, inconsistent with real-time records from the url,
unless I paste and open/refresh the url in my browser again. I wonder if this is a problem with cache, and how should I alter my code?
library(shiny)
shinyApp(
ui <- fluidPage(
column(3,
selectInput("station", "Select station",
c("a", "b")),
tableOutput("table")
)
),
server <- function(input, output) {
df <- eventReactive(input$station, {
if (input$station == "a") {
tail(read.csv("https://datagarrison.com/users/300234062103550/300234062107550/temp/Dawson_Creek__008.txt",
sep = "\t", skip = 2)[, c("Date_Time", "Rain_2440445_mm")], 8)
} else {
tail(read.csv("http://datagarrison.com/users/300234062103550/300234064336030/temp/10839071_004.txt",
sep = "\t", skip = 2)[, c("Date_Time", "Rain_2007476_mm")], 8)
}})
output$table <- renderTable(
df()
)
})
Update: It turned out that it is the server itself experiencing the update issue instead of the code. However, the answer shows a helpful approach.