Credit belongs to Hadley
Wickham, the creator of the
original CRAN package download shiny application. This is my own version
of his project using the bs4Dash
package and including Python data.
The download logs from PyPI in the dashboard requires the use of
BigQuery, which is accomplished in R through the use of the bigrquery
package. BigQuery has a free tier, which offers 10 GB storage and up to
1 TB queries per month. For working with Google APIs, refer to the
gargle
package, which bigrquery
uses to deal with authentication,
and its
vignettes.
In order to use BigQuery:
Set up a Google Cloud account here and create a new project.
Enable API for Google Cloud platform (GCP) as specified in the
gargle
documentation
under the section Enable API(s).
Set up billing for Google Cloud account (see documentation). No payment is required if usage stays under free tier.
Create service account and create key (.json file).
Set environment variable:
# Name of the project created
Sys.setenv(BIGQUERY_TEST_PROJECT = "project_name")
# Service account key
Sys.setenv(path_to_bq_token = "path_to_key_json.json")
# For non-interactive use
bq_auth(path = Sys.getenv("path_to_bq_token"))
gargle
documentation.Install TrackerDashboard from GitHub with:
# install.packages("devtools")
devtools::install_github("YangWu1227/tracker-dashboard")
To run app.R:
library(TrackerDashboard)
# Service account token ---------------------------------------------------
bq_auth(path = Sys.getenv("path_to_bq_token"))
# Pool object -------------------------------------------------------------
pool <- dbPool(
drv = bigquery(),
project = "bigquery-public-data",
dataset = "pypi",
billing = bq_test_project()
)
onStop(function() {
poolClose(pool)
})
# Variables for default R text inputs -------------------------------------
top5 <- cran_top_downloads(count = 5)$package
today <- Sys.Date() - 1
last_month <- today - 60
runApp(top5, today, last_month, pool)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.