I created a Shiny app. Basically, inside the R code, the data is retrieved from the URL link (so App is using only it), which downloads data in excel format. The data in the URL is refreshed every hour. As a result, ideally, the Shiny app gets every time the latest data.
Question: Is it possible to do in this way that the latest data is depicted on the web page (of Shiny app) every time users 1) open the web page with Shiny app and 2) press Refresh button on the web page with Shiny app?
Data is always refreshing at H+30. I.E. information for the 10 am is published at 11:30 and etc. So, I want kind of refresh button, which helps run the script in the app from the beginning.
The table is following:
library(shiny)
#library(httr)
#library(XML)
library(dplyr)
library(ggplot2)
#library(data.table)
library(formattable)
library(reshape2)
library(ggthemes)
library(shinyjs)
library(V8)
df <- read.csv2(paste("path"))[-2]
names(df) <- c("Region","Date","Imbalance")
df$Date <- as.POSIXct(df$Date , format="%Y-%m-%d %H")
df$Imbalance<-as.numeric(df$Imbalance)
df<- as.data.frame(na.omit(dcast(df, Date ~ Region, value.var = "Imbalance")))
df<-df %>% arrange(desc(Date))
df[2:5]<-lapply(df[2:5], as.numeric)
df[2:5]<-round(df[2:5],0)
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Imbalance volumes"),
# Sidebar with slider input to select date range
sidebarLayout(
sidebarPanel(
# Add a Slider Input to select date range
#sliderInput
dateRangeInput("Date_range_selector", "Select Date Range",
start = as.Date(paste(Sys.Date()-2,"00:00:00",sep = " "),"%Y-%m-%d %H"),
end = as.Date(paste(Sys.Date(),"00:00:00",sep = " "),"%Y-%m-%d %H"),
min = as.Date("2015-01-01 00:00:00","%Y-%m-%d %H"),
max = as.Date("2020-12-01 00:00:00","%Y-%m-%d"),
#value=c(as.Date(Sys.Date()-14),as.Date(Sys.Date())),
#format ="%Y-%m-%d"
)
),
# plot graphs
mainPanel(tabsetPanel(
tabPanel("Stat",
h3(helpText("Imbalance volumes")),
formattableOutput("formattableexample"))
)
)
))
server <- function(input, output) {
############Plot Prices and histogram###############
test2<-reactive({
df %>%
filter(between(as.Date(Date), input$Date_range_selector[1], input$Date_range_selector[2]))
})
output$formattableexample <- renderFormattable({
formattable(test2(),
align =c("l","c","c","c","c", "c", "c", "c", "r"),
list("Date" = formatter("span", style = ~ style(color = "grey",font.weight = "bold"))
))
})
}
shinyApp(ui = ui, server = server)