library(rcw) knitr::opts_chunk$set(echo = FALSE, out.width="100%", message = FALSE ## , ## eval = FALSE )
Create single chart from SDMX query
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2015&endTime=2015" chartconfig <- create_config( sdmx_data_query = query, type = "BarChart", highlight = list("PRINTO01", c("BEL", "FIN", "FRA")), baseline = list("PRMNTO01", "AUS") ## language = "fr" )
res_ls <- post_config( config = chartconfig, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", path = "../examples/bar.json" # write config to disk ) ## browseURL(res_ls$viewer_url) knitr::include_url(res_ls$viewer_url, height = "750px")
knitr::include_graphics("https://raw.githubusercontent.com/r4io/rcw/master/assets/img/screenshot_post_single_config.png")
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2015&endTime=2015" scatter_config <- create_config( sdmx_data_query = query, type = "ScatterChart", highlight = list(LOCATION = "AUT", LOCATION = "FRA", LOCATION = "CZE" ), chart_dimension = list(id = "SUBJECT", x = "PRINTO01", y = "PRMNTO01", mode = "percent"), baseline = list(LOCATION = "FIN") ,x_axis = list(min = -2, max = 4, step = 1, pivot = 1), y_axis = list(min = -2) )
scatter_res <- post_config( config = scatter_config, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", post = TRUE, path = "../examples/scatter.json" ) ## str(scatter_config) ## scatter_res$viewer_url ## paste0("http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService/share?id=", scatter_res$id) knitr::include_url(scatter_res$viewer_url, height = "500px")
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2015&endTime=2015" stacked_bar_config <- create_config( sdmx_data_query = query, type = "StackedBarChart", highlight = list(c("AUT", "BEL", "FIN")), baseline = list("FRA"), chart_dimension = list(id = "LOCATION", mode = "value") )
stacked_bar_res <- post_config( config = stacked_bar_config, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", post = TRUE, path = "../examples/stacked_bar.json" ) ## str(stacked_bar_config) ## stacked_bar_res$viewer_url ## paste0("http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService/share?id=", stacked_bar_res$id) knitr::include_url(stacked_bar_res$viewer_url, height = "500px")
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2010&endTime=2015" timeline_config <- create_config( sdmx_data_query = query, type = "TimelineChart", highlight = list("PRINTO01", c("AUT", "BEL", "FIN")), baseline = list("PRINTO01", "FRA"), y_axis = list(min = -5, max = 10, step = 5) # max is ignored if larger values in data )
timeline_res <- post_config( config = timeline_config, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", post = TRUE, path = "../examples/timeline.json" ) ## str(timeline_config) ## timeline_res$viewer_url ## paste0("http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService/share?id=", timeline_res$id) knitr::include_url(timeline_res$viewer_url, height = "500px")
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2015&endTime=2015" row_config <- create_config( sdmx_data_query = query, type = "RowChart", highlight = list("PRINTO01", c("AUT", "BEL", "FIN")), baseline = list("PRINTO01", "FRA") )
row_res <- post_config( config = row_config, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", post = TRUE, path = "../examples/row.json" ) ## str(row_config) ## row_res$viewer_url ## paste0("http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService/share?id=", row_res$id) knitr::include_url(row_res$viewer_url, height = "700px")
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2015&endTime=2015" vertical_symbol_config <- create_config( sdmx_data_query = query, type = "VerticalSymbolChart", chart_dimension = list(id = "SUBJECT"), highlight = list(c("DNK", "AUS", "CZE")), baseline = list("CAN") )
vertical_symbol_res <- post_config( config = vertical_symbol_config, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", post = TRUE, path = "../examples/vertical_symbol.json" ) ## str(vertical_symbol_config) ## vertical_symbol_res$viewer_url ## paste0("http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService/share?id=", vertical_symbol_res$id) knitr::include_url(vertical_symbol_res$viewer_url, height = "700px")
query <- "KEI/PRINTO01+PRMNTO01.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA.GP.A/all?startTime=2015&endTime=2015" horizontal_symbol_config <- create_config( sdmx_data_query = query, type = "HorizontalSymbolChart", chart_dimension = list(id = "SUBJECT"), highlight = list(c("DNK", "AUS", "CZE")), baseline = list("CAN") )
horizontal_symbol_res <- post_config( config = horizontal_symbol_config, ## url = "http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService", url = "https://stats.oecd.org/share", post = TRUE, path = "../examples/horizontal_symbol.json" ) ## str(horizontal_symbol_config) ## horizontal_symbol_res$viewer_url ## paste0("http://dotstatcor-dev2.main.oecd.org/PMShareIntranetService/share?id=", horizontal_symbol_res$id) knitr::include_url(horizontal_symbol_res$viewer_url, height = "700px")
Create one chart per variable
var_ls <- list( list(code = "PRINTO01", label = "Industrial Production"), list(code = "PRMNTO01", label = "Total Manufacturing") ) cou_c <- c("AUS", "AUT", "BEL", "CAN", "CHL", "CZE", "DNK", "EST", "FIN", "FRA") cou_str <- paste(cou_c, collapse = "+") subtitle <- c("Measure: Growth previous period", "Frequency: Annual", "Time: 2015") query_url_ls <- lapply(var_ls, function(x) { query1 <- paste(x$code, cou_str, "GP", "A", sep = ".") query2 <- file.path("KEI", query1, "all?startTime=2015&endTime=2015") config <- create_config(sdmx_data_query = query2, title = "Key Short-Term Economic Indicators", subtitle = c(x$label, subtitle), type = "BarChart", highlight = list(c("BEL", "FIN", "FRA")), baseline = list("AUS"), language = "fr", path = "../examples/bar.json" # template ) list( code = x$code, label = x$label, config = config ) }) ## str(query_url_ls)
chart_url_c <- ## sapply(query_url_ls, lapply(query_url_ls, function(x) post_config(config = x$config, url = "https://stats.oecd.org/share", post = TRUE, path = paste0("../examples/multi_", x$code, ".json") )) ## print(chart_url_c) str(chart_url_c) knitr::include_url(chart_url_c[[1]]$viewer_url, height = "700px") knitr::include_url(chart_url_c[[2]]$viewer_url, height = "700px")
## create temporary file outfile <- tempfile(pattern = "chartconfig_", fileext = ".json") ## export configuration to disk post_config(config = chartconfig, show = TRUE, path = outfile) ## read back into R chartconfig_reimported <- jsonlite::read_json(path = outfile) str(chartconfig_reimported)
chartconfig <- create_config( sdmx_data_query = query, # title = "Key Short-Term Economic Indicators", # subtitle = c("Measure: Growth previous period", # "Frequency: Annual", # "Time: 2015"), # source_url = "http://stats.oecd.org:80/Index.aspx?DataSetCode=KEI", # source_label = "Key Short-Term Economic Indicators", logo = TRUE, owner = TRUE, type = "BarChart", # "RowChart" highlight = list("PRINTO01", c("BEL", "FIN", "FRA")), baseline = list("PRMNTO01", "AUS") ## , ## width = 800, ## height = 500, ## path = jsonfile ## path = "../examples/bar.json" ) str(chartconfig)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.