From 09a9e36ebca999377a6ce0bd2ba321f9145bd5c3 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Fri, 19 Jul 2024 07:49:13 -0500 Subject: [PATCH 1/3] Chapter 29 revisions More slide-like. --- 29-quarto_formats.Rmd | 185 ++++++++++++++++++++---------------------- 1 file changed, 87 insertions(+), 98 deletions(-) diff --git a/29-quarto_formats.Rmd b/29-quarto_formats.Rmd index 03ffd0d..a9771e7 100644 --- a/29-quarto_formats.Rmd +++ b/29-quarto_formats.Rmd @@ -2,114 +2,99 @@ **Learning objectives:** -- Give a brief overview of some options for communicating your results with Quarto, from static and interactive documents to presentations to websites and books. +- Render Quarto documents to different formats. +- Set output options for Quarto documents in different formats. +- Render documents in various formats from Quarto documents. +- Render presentations in various formats from Quarto documents. +- Create interactive web pages with Quarto. +- Group Quarto documents together into websites and books. +- Find information about other Quarto formats. +## Setting output type {-} -## Setting output type +2 ways to set qmd output format: -There are two ways to set the output of a document: +1. YAML header: - -1. Modify the YAML header: -```{r eval=FALSE} +```{yaml} title: "Diamond sizes" format: html ``` -2. Call quarto::quarto_render() by hand: +2. `quarto::quarto_render()`: ```{r eval=FALSE} - quarto::quarto_render("diamond-sizes.qmd", output_format = c("docx", "pdf")) ``` -Note: You can produce multiple types of output since the `output_format` argument can take a list of values - -## Output options - -- You can find the complete list of Quarto output formats at -- Many formats share some output options, but others have options that are format specific. - - Ex. including a table of content vs. code folding -- To render to all formats specified in the YAML of a document, you can use `output_format = "all"`. - -```{r eval=FALSE} -quarto::quarto_render("diamond-sizes.qmd", output_format = "all") -``` - -## Documents +Note: `output_format` can have multiple values -- There are several basic variations off HTML for generating different types of documents. To name a few, examples are: - - `pdf` makes a PDF with LaTeX +## Output options {-} - - `docx` for Microsoft Word (.docx) documents. +- [Quarto output formats](https://quarto.org/docs/output-formats/all-formats.html) +- Some options shared (`toc: true`) +- Some format-specific (`code-fold: true` for `format: html`) +- `default` to use defaults for format - - `gfm` for a GitHub Flavored Markdown (.md) document. - - - `ipynb` for Jupyter Notebooks (.ipynb). - - -```{r eval=FALSE} +```{yaml} format: html: - toc: true #include table of contents - toc_float: true #make table of contents floating + toc: true + toc_float: true pdf: default docx: default ``` -Note: use special syntax (i.e. `pdf: default`) if you don’t want to override any default options. +- `output_format = "all"` for all specified formats -## Presentations +## Documents {-} -- When using Quarto to produce presentations, you get less visual control than with a tool like PowerPoint, but the upside is you can automatically insert the results of your R code into your presentation. -- Presentations work by dividing your content into slides, with a new slide beginning at each second (`##`) level header. - - First (`#`) level headers indicate the beginning of a new section with a section title slide. -- Quarto supports a variety of presentation formats, including: +Document formats: - - `revealjs` - HTML presentation with revealjs - - - `pptx` - PowerPoint presentation - - - `beamer` - PDF presentation with LaTeX Beamer. +- `pdf` = PDF with LaTeX +- `docx` = Microsoft Word +- `gfm` = GitHub Flavored Markdown +- `ipynb` = Jupyter Notebooks -- You can read more about creating presentations with Quarto at . +## Presentations {-} -## Interactivity +- `#` = new section, `##` = new slide -- HTML documents created with Quarto can contain interactive components as well. -- Two example options for including interactivity in your Quarto documents are htmlwidgets and Shiny. - - **htmlwidgets** are R functions that produce interactive HTML visualizations - - `Shiny` is a package that allows you to create interactivity using R code +Presentation formats: -## htmlwidgets +- `revealjs` = HTML presentation with revealjs +- `pptx` = PowerPoint presentation +- `beamer` = PDF presentation with LaTeX Beamer -- htmlwidgets provide client-side interactivity, meaning all the interactivity happens in the browser, independently of R. -- You don’t need to know anything about HTML or JavaScript to use them because all the details are wrapped inside the package. -- There are many packages that provide htmlwidgets, including: - - [`leaflet`](https://rstudio.github.io/leaflet/) for interactive map - - [`dygraphs`](https://rstudio.github.io/dygraphs) for interactive time series visualizations. - - - [`DT`](https://rstudio.github.io/DT/) for interactive tables. - - - [`threejs`](https://bwlewis.github.io/rthreejs) for interactive 3d plots. - - - [`DiagrammeR`](https://rich-iannone.github.io/DiagrammeR) for diagrams (like flow charts and simple node-link diagrams). +More at [quarto.org/docs/presentations](https://quarto.org/docs/presentations) -- To learn more about htmlwidgets and see a complete list of packages that provide them visit . +## Interactivity {-} -## Shiny +`format: html` support interactivity -- Shiny interactions occur on the server-side, meaning you can write interactive apps without knowing JavaScript, but you need a server to run them on. +- {htmlwidgets} = pure client-side interactivity +- {shiny} = complex interactivity with server-side processing +- {shinylive} (not in book) = complex interactivity without server -- To call Shiny code from a Quarto document, add `server: shiny` to the YAML header: -```{r eval=FALSE} +## htmlwidgets {-} + +- Handles HTML & JavaScript for you +- Many packages provide {htmlwidgets}: + - [{leaflet}](https://rstudio.github.io/leaflet/) = maps + - [{dygraphs}](https://rstudio.github.io/dygraphs) = time series visualizations + - [{DT}](https://rstudio.github.io/DT/) = tables + - [{threejs}](https://bwlewis.github.io/rthreejs) = 3d plots + - [{DiagrammeR}](https://rich-iannone.github.io/DiagrammeR) = flow charts, node-link diagrams, etc + - More at [htmlwidgets.org](https://www.htmlwidgets.org) + +## Shiny {-} + +```{yaml} title: "Shiny Web App" format: html server: shiny ``` -- Then you can use the “input” functions to add interactive components to the document: - ```{r eval=FALSE} library(shiny) @@ -117,45 +102,49 @@ textInput("name", "What is your name?") numericInput("age", "How old are you?", NA, min = 0, max = 150) ``` -- And you also need a code chunk with chunk option `context: server` which contains the code that needs to run in a Shiny server. +- Code chunk with `#| context: server` for server-side code -## Websites and books +## ShinyLive {-} -- With a bit of additional infrastructure, you can use Quarto to generate a complete website or book: +- Uses [WebR](https://docs.r-wasm.org/webr/latest/) +- No server side +- Can't (yet?) communicate with internet +- Can't hide secrets from user - - Put your `.qmd` files in a single directory. `index.qmd` will become the home page. - - - Add a YAML file named `_quarto.yml` that provides the navigation for the site. In this file, set the project type to either `book` or `website`, e.g.: - -```{r eval=FALSE} -project: - type: book -``` +[quarto-ext.github.io/shinylive](https://quarto-ext.github.io/shinylive/) + +## Websites and books {-} -- Read more at about Quarto websites and about books. +Quarto projects can group `.qmd`s into websites or books -- Note: [R4DS 2E](r4ds.hadley.nz) is itself a quarto book. You can find the code to render it on your own here: . The [Quarto website](https://quarto.org/) itself was made with Quarto. You can find the code here: . +- Put `.qmd` files in single directory (confirm) +- `index.qmd` = home page +- `_quarto.yml` specifies structure -## Other formats +```{yaml} +project: + type: book +``` -- Quarto offers even more output formats. For example: +- More at [quarto.org](https://quarto.org): + - [/docs/websites](https://quarto.org/docs/websites) + - [/docs/books](https://quarto.org/docs/books) - - You can write journal articles using Quarto Journal Templates: . - - - You can output Quarto documents to Jupyter Notebooks with `format: ipynb`: . +## Other formats {-} -- See for a list of even more formats. +- [Quarto Journal Templates](https://quarto.org/docs/journals/templates.html) +- [More at quarto.org](https://quarto.org/docs/output-formats/all-formats.html) -## Resources +## Resources {-} -- [Quarto Pub](https://quartopub.com/): Create documents, websites, presentations, books, and blogs in Quarto, then securely publish them to the web with the Quarto CLI, the easiest way to publish and share on the web. -- [Awesome Quarto](https://github.com/mcanouil/awesome-quarto): A curated list of Quarto talks, tools, examples & articles! -- Quarto documentation: -- Quarto GitHub repo: +- [quarto.pub](https://quartopub.com/): Quarto publishing platform +- [github.com/mcanouil/awesome-quarto](https://github.com/mcanouil/awesome-quarto): Awesome Quarto (Quarto talks, tools, etc) +- [quarto.org](https://quarto.org/): Quarto documentation +- [github.com/quarto-dev](https://github.com/quarto-dev) -## Meeting Videos +## Meeting Videos {-} -### Cohort 5 +### Cohort 5 {-} `r knitr::include_url("https://www.youtube.com/embed/2MGp74nb2ig")` @@ -187,7 +176,7 @@ project: ``` -### Cohort 6 +### Cohort 6 {-} `r knitr::include_url("https://www.youtube.com/embed/qQrnNef9fkM")` @@ -213,7 +202,7 @@ https://exts.ggplot2.tidyverse.org/gallery/ -### Cohort 7 +### Cohort 7 {-} `r knitr::include_url("https://www.youtube.com/embed/vkjYlBK9-9c")` @@ -230,7 +219,7 @@ https://exts.ggplot2.tidyverse.org/gallery/ -### Cohort 8 +### Cohort 8 {-} `r knitr::include_url("https://www.youtube.com/embed/7kW7DEWPVZ8")` From 32d992d7ccb942012fef6323c6e5769301671dde Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Fri, 19 Jul 2024 08:00:26 -0500 Subject: [PATCH 2/3] Disable broken scraping example --- 24-web_scraping.Rmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/24-web_scraping.Rmd b/24-web_scraping.Rmd index b86b447..762cfff 100644 --- a/24-web_scraping.Rmd +++ b/24-web_scraping.Rmd @@ -45,7 +45,9 @@ HTML = **H**yper**T**ext **M**arkup **L**anguage [IMDB data from the Internet Archive](https://web.archive.org/web/20220201012049/https://www.imdb.com/chart/top/) -```{r web_scraping-tables, eval=TRUE} +(currently times out, disabled for now; next cohort should revise!) + +```{r web_scraping-tables, eval=FALSE} url <- "https://web.archive.org/web/20220201012049/https://www.imdb.com/chart/top/" html <- read_html(url) html |> From 01efe2589c0f0bc749b6b9ea811c4d3420763f8d Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Fri, 19 Jul 2024 08:38:18 -0500 Subject: [PATCH 3/3] Disable another broken scraping example --- 24-web_scraping.Rmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/24-web_scraping.Rmd b/24-web_scraping.Rmd index 762cfff..146f824 100644 --- a/24-web_scraping.Rmd +++ b/24-web_scraping.Rmd @@ -64,7 +64,9 @@ html |> ## Example: Specific table {-} -```{r web_scraping-html_element, eval=TRUE} +(See "Example: Table" slide above; fix that then this) + +```{r web_scraping-html_element, eval=FALSE} html |> html_element("table") |> html_table()