knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = TRUE, eval = FALSE )
DataverkR is a R wrapper for the python library Dataverk. It has support for creating and publishing datapackages, with Plotly figures and R dataframes.
To create and publish a datapackage you need to import DataverkR. Also if you want to add Plotly figures you need to import Plotly.
You must have Python installed on your machine in order to run this package. The first time you use any python call in R, you will get a warning:
No non-system installation of Python could be found. Would you like to download and install Miniconda? Miniconda is an open source environment management system for Python. See miniconda for more details.
The warning will only be given one time on each computer and only if Python is not actually installed.
You can install a Python environment in several ways, none of them very good on Windows. The simplest from a desktop installation of R is to download and install it from Python and then follow this excellent guide at RStudio support.
In order to run Python in R, you need the reticulate package.
install.packages("reticulate")
library(reticulate) library(dataverkr) library(plotly)
To create a datapackage you need to supply some metadata in a named list. To see which field are needed see the datapackages documentation.
metadata <- list(title = 'DataverkR example', temporal = list(from = '2020-09-16', to='2021-11-05'))
To create the datapackage, simply run:
dp <- create_dp(metadata)
If the metadata is incomplete, an error will occur.
To add a dataframe:
# Creating dataframe country <- c("Norge","Sverige", "Danmark") numberOf <- c(200, 300, 500) df <- data.frame(country, numberOf) add_resource(dp = dp, dataframe = df, resource_name = 'some_dataframe', resource_description = 'This is a resource example')
This dataframe will be available for download as .csv file.
To add a Plotly figure:
# Creating plotly figure fig <- plot_ly(df, x = ~country, y = ~numberOf, type = 'bar') add_fig(dp = dp, fig = fig, title = 'Some plotly figure', description = 'This is a plotly figure example')
To create a Plotly figure in R, see Plotly.
Finally to publish the datapackage:
publish(dp)
Contact us in #data-catalog-intern
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.