Skip to content

Commit c8913ec

Browse files
author
Susan Vanderplas
committed
Fix issues in api chapter and interactive graphics duplication
1 parent 9fe5d14 commit c8913ec

File tree

5 files changed

+130
-1219
lines changed

5 files changed

+130
-1219
lines changed

_quarto.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ format:
159159
body-width: 1200px
160160
css: ['build_deps/style.css']
161161
highlight-style: a11y
162-
theme:
163-
light: ['flatly', build_deps/_variables-flatly.scss, build_deps/theme.scss]
164-
dark: ['darkly', build_deps/_variables-darkly.scss, build_deps/theme.scss]
162+
# theme:
163+
# light: ['flatly', build_deps/_variables-flatly.scss, build_deps/theme.scss]
164+
# dark: ['darkly', build_deps/_variables-darkly.scss, build_deps/theme.scss]
165165
code-link: true
166166
include-in-header: "build_deps/header.html"
167167
code-copy: true

part-advanced-topics/05-APIs.qmd

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -84,56 +84,22 @@ HTTP requests have a request header and a request body.
8484

8585
HTTP requests will return a response code.
8686

87-
In general, 2xx is Success, 3xx is 'address moved', 4xx is 'client screwed up', and 5xx is 'server screwed up', but you can find a full list [here](https://www.coderstool.com/http-response-codes).
88-
You're probably familiar with a 404 error, which
87+
I prefer the very general summary [@AllHTTPStatus2023]:
8988

90-
::: column-margin
91-
Julia Evans [@evansQuestionsHTTPStatus2020] has some lovely Q&A flashcards on HTTP codes, and there is a cartoon-style [zine]( https://wizardzines.com/zines/http/) for sale that is really lovely as well.
92-
:::
93-
94-
::: {.callout collapse=true}
95-
#### There's a lovely poem from Rester Test [source](https://medium.com/@t79877005/api-response-codes-poem-451ca17e8f2c) that explains response codes and their meanings
96-
97-
```
98-
In the world of tech, there’s a curious thing,
99-
Called API requests that make devices sing.
100-
They’re like little messages that devices send,
101-
To get a response from their API friend.
102-
103-
API requests are like a note,
104-
Sent to an API with a hopeful mote.
105-
They can ask for data or do some work,
106-
And wait for a response, like a playful quirk.
89+
> 1xx Here's what I'll do.
90+
2xx Here's what you want.
91+
3xx I don't have what you want but I know who does.
92+
4xx It didn't work but it's your fault.
93+
5xx It didn't work and it's my fault.
10794

108-
But sometimes the API friend may say,
109-
“I cannot do as you request today”.
110-
And send a response with a special code,
111-
To let the device know what’s on the road.
11295

113-
Response codes are like a language too,
114-
And help devices know what to do.
115-
There’s 200 for success, and 400 for bad,
116-
And 500 for errors, that makes devices sad.
117-
118-
With response codes, the devices know,
119-
If their requests are a friend or foe.
120-
They can take action based on the code,
121-
And keep the tech world in a secure mode.
122-
123-
So next time you send an API request,
124-
And wait for a response with bated breath,
125-
Remember that codes are the language they speak,
126-
And help devices find what they seek.
127-
128-
API requests and response codes together,
129-
Are the backbone of tech’s forever.
130-
They help devices connect and communicate,
131-
And make our world a much better state.
132-
```
96+
You can find a full list [here](https://www.coderstool.com/http-response-codes).
97+
You're probably familiar with a 404 error, which is "File not found" -- that is, you passed in an address that isn't valid.
13398

99+
::: column-margin
100+
Julia Evans [@evansQuestionsHTTPStatus2020] has some lovely Q&A flashcards on HTTP codes, and there is a cartoon-style [zine](https://wizardzines.com/zines/http/) for sale that is also very nice.
134101
:::
135102

136-
137103
## Accessing APIs without Authentication
138104

139105
:::: demo
@@ -234,13 +200,14 @@ Make sure you have the `httr2` library installed (it's a dependency of a lot of
234200

235201
```{r}
236202
library(httr2)
203+
library(xml2)
204+
237205
req <- request("https://evilinsult.com/generate_insult.php/?lang=el&type=xml") |>
238206
req_perform()
239207
240208
resp_raw(req) # response header and body
241209
xml_resp <- resp_body_string(req) # response body, encoded as a string
242210
243-
library(xml2)
244211
read_xml(xml_resp)
245212
```
246213

@@ -277,6 +244,12 @@ You may need to make several requests to get the data you want.
277244

278245
```{r}
279246
library(httr2)
247+
library(lubridate)
248+
library(dplyr)
249+
library(tidyr)
250+
library(ggplot2)
251+
library(purrr)
252+
280253
uastring <- "R/python data science demos, [email protected]" # Set this to YOUR email, please!
281254
282255
pointsreq <- request("https://api.weather.gov/points/35.339508,-97.486702") |>
@@ -294,12 +267,11 @@ forecastreq <- request(req_url_str) |>
294267
forecastjson <- resp_body_json(forecastreq)
295268
forecastjson$properties$periods[[1]]
296269
297-
library(lubridate)
298-
moore_temps <- tibble(start_time = map_vec(forecastjson$properties$periods, "startTime"),
299-
temp = map_vec(forecastjson$properties$periods, "temperature")) |>
270+
moore_temps <- tibble(
271+
start_time = map_vec(forecastjson$properties$periods, "startTime"),
272+
temp = map_vec(forecastjson$properties$periods, "temperature")) |>
300273
mutate(start_time = ymd_hms(start_time))
301274
302-
library(ggplot2)
303275
ggplot(moore_temps, aes(x = start_time, y = temp)) + geom_line()
304276
305277
```
@@ -415,6 +387,7 @@ Sys.getenv("API_SECRET")
415387
###### Python {-}
416388

417389
```{python}
390+
#| eval: false
418391
%pip install python-dotenv
419392
```
420393

part-advanced-topics/07-intro-interactive-graphics.qmd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# Interactive Graphics {#sec-interactive-graphics}
2-
3-
4-
# Animated and Interactive Graphics
1+
# Animated and Interactive Graphics {#sec-interactive-graphics}
52

63
Interactive and animated graphics are one of the major advantages of using the `quarto` or `Rmarkdown` (or `Jupyter`) ecosystems - because you can easily create web pages in markdown (without the pain of HTML), you aren't limited by paper any more.
74
This chapter will focus on two different technologies that allow you to create different types of interactive charts, graphs, and interfaces: Shiny, and Plotly.

0 commit comments

Comments
 (0)