report_data_import.Rmd
On the NoviSci Web Platform the report system supports two types of reports:
This article describes importing the data for option 2.
A data set for dynamic reports is a small-ish rectangular block of data that is used to render one or more visualizations on a report page. This can be imported into the platform from an R dataframe.
At a high level, the columns of this data set will represent either subgroups (ie, race, age group, sex, etc.) or values to be plotted/displayed (count, mean, percent, etc).
For more details on the format and granularity of data sets see the Report Data Format article.
When importing data into the platform you will need the following information:
sex <- c(NA, NA, NA, "M", "M", "M", "F", "F", "F") x <- c("2010-01-01", "2011-01-01", "2012-01-01", "2010-01-01", "2011-01-01", "2012-01-01", "2010-01-01", "2011-01-01", "2012-01-01") y <- sample(1:100, length(x)) df <- data.frame(sex, x, y) nswpr::import_report_data_df(df, report_id = "p0000", data_set_key = "random_values", subgroups = list("sex"), data_set_label = "Random Values", chart_types = list("line", "bar"))
Sunburst and sankey visualizations have a nested structure that needs to be imported as a list of lists. All of the inputs to the import function are the same as the dataframe version, except the first input is a list of lists.
sunburst_data <- list( list( # This list can be repeated for each subgroup combination (ie, 2 more - one for male and one for female) sex = NA, # There can be more than one subgroup if we want to have multiple filters/strata options types = list( t1 = "Treatment One", t2 = "Treatment Two" ), # This is metadata about the sunburst (labels) data = list( # This is the sunburst data itself list( type = "t1", value = 23, children = list( list( type = "t1", value = 5 ), list( type = "t2", value = 7 ) ) ), list( type = "t2", value = 58, children = list( list( type = "t1", value = 3 ), list( type = "t2", value = 5 ) ) ) ) ) ) nswpr::import_report_data_nested(sunburst_data, report_id = "p0000", data_set_key = "my_sunburst_data", subgroups = list("sex"), data_set_label = "My Sunburst Data", chart_types = list("sunburst"))