Hi all,
I would like to show my current workflow and get some suggestion about how to improve it.
I created a flexdashboard using some data I take from a Postgres database.
I feel it is full of errors and bad practices and I would like to have some suggestions about how to refactor my code.
Here how my project structure looks like:
.
└── my_awesome_report
├── set_up.R
├── get_data.R
├── data
│ └── my_data.RData
├── my_awesome_report.Rmd
└── .gitignore
-
set_up.R contains libraries & database connection via RPostgres.
This file starts with rm(list=ls()); I know, but where to find some resources on how to correct this error?
-
get_data.R gets data via dbGetQuery(db, query), closes the connections via dbDisconnect(db), applies transformations via dplyr then saves the final dataframe in the /data folder as my_data.RData.
- I show my data in a
flexdashboard template, hosted on shinyapp.io.
In r setup, I load my libraries (again!) and data, run and show some tables via kable and some other nice things, and then publish it.
{r setup, include=FALSE}
# load libraries
library(plotly)
library(knitr)
library(kable)
# load data
load('data/my_data.RData')
I want my dashboard to be updated on a daily basis; or add a button that the user can press like "Update dashboard" and refreshes the whole dashboard data.
And here is where my process gets very cumbersome.
I run manually:
set_up.R
get_data.R
- render my flexdashbaord
- publish it on the shinyapp.io
How can I make this process automatic, with a chronjob?
The main structure is there but I feel that the whole process is approached in the wrong way.
please let me know your opinion.
Vincenzo