From c8089e62102bcbf133d6c86dc812346deec64898 Mon Sep 17 00:00:00 2001 From: jesimeon Date: Thu, 24 Oct 2024 19:05:33 +0000 Subject: [PATCH 1/2] Import JSON example --- r/samples/import_json/simple_import_json.qmd | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 r/samples/import_json/simple_import_json.qmd diff --git a/r/samples/import_json/simple_import_json.qmd b/r/samples/import_json/simple_import_json.qmd new file mode 100644 index 0000000..a9ee572 --- /dev/null +++ b/r/samples/import_json/simple_import_json.qmd @@ -0,0 +1,56 @@ +--- +title: "Simple R Example to Import JSON" +date: "2024-10-24" +output: html +execute: + echo: true +--- + +# This is a very basic quarto document for sharing your code + + +This is a simple example of how to import a json. +JavaScript Object Notation, or JSON, is a semi-structured format often used by web applications and REST APIs to exchange data. +To run this, pacman and rmarkdown will need to be installed. + +```{r, prep-for-example} + +# Install some packages +if (!require("pacman")) install.packages("pacman") +if (!require("readr")) install.packages("readr") + + +# Load necessary library +pacman::p_load(pacman, tidyverse, jsonlite, rmarkdown) +``` + +Fetch some data by calling an API + +```{r, get-some-data} + +# Call an API to get JSON data +data <- "https://ghoapi.azureedge.net/api/Dimension" %>% + fromJSON() %>% + print() + +``` + +::: {.callout-note} +This API call only shows available dimensions. +::: + +That is how to fetch and read a JSON file. + +```{r, reformat-data-for-vis} +# Re-format the content +data %>% + toJSON(pretty = T) %>% + print() + +``` + +::: {.callout-tip} +You can create callout-tips! Just use the `callout-tip` class. +::: + + From d4479ab59bced0dab713ab00c74d7d1b571a7e01 Mon Sep 17 00:00:00 2001 From: jesimeon Date: Mon, 28 Oct 2024 19:12:29 +0000 Subject: [PATCH 2/2] JS Import JSON sample --- r/samples/import_json/simple_import_json.qmd | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/r/samples/import_json/simple_import_json.qmd b/r/samples/import_json/simple_import_json.qmd index a9ee572..72dde2e 100644 --- a/r/samples/import_json/simple_import_json.qmd +++ b/r/samples/import_json/simple_import_json.qmd @@ -8,7 +8,6 @@ execute: # This is a very basic quarto document for sharing your code - This is a simple example of how to import a json. JavaScript Object Notation, or JSON, is a semi-structured format often used by web applications and REST APIs to exchange data. To run this, pacman and rmarkdown will need to be installed. @@ -17,18 +16,16 @@ To run this, pacman and rmarkdown will need to be installed. # Install some packages if (!require("pacman")) install.packages("pacman") -if (!require("readr")) install.packages("readr") - # Load necessary library -pacman::p_load(pacman, tidyverse, jsonlite, rmarkdown) +pacman::p_load(pacman, readr, rmarkdown, tidyverse, jsonlite, rmarkdown) ``` Fetch some data by calling an API ```{r, get-some-data} -# Call an API to get JSON data +# Call an API to get JSON data in a tabular format data <- "https://ghoapi.azureedge.net/api/Dimension" %>% fromJSON() %>% print()