Skip to content

Commit 15f6a25

Browse files
committed
Remove poor exercise in scaling-functions
hadley#416
1 parent 64d5e21 commit 15f6a25

File tree

1 file changed

+0
-61
lines changed

1 file changed

+0
-61
lines changed

scaling-functions.Rmd

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -292,67 +292,6 @@ server <- function(input, output, session) {
292292

293293
But this feels weird as the function is still fundamentally coupled to this app because it only affects a control named "wizard" with a very specific set of tabs.
294294

295-
## Exercises
296-
297-
1. The following app plots user selected variables from the `msleep` dataset for three different types of mammals (carnivores, omnivores, and herbivores), with one tab for each type of mammal.
298-
Remove the redundancy in the `selectInput()` definitions with the use of functions.
299-
300-
```{r, eval = FALSE}
301-
library(tidyverse)
302-
303-
ui <- fluidPage(
304-
selectInput(inputId = "x",
305-
label = "X-axis:",
306-
choices = c("sleep_total", "sleep_rem", "sleep_cycle",
307-
"awake", "brainwt", "bodywt"),
308-
selected = "sleep_rem"),
309-
selectInput(inputId = "y",
310-
label = "Y-axis:",
311-
choices = c("sleep_total", "sleep_rem", "sleep_cycle",
312-
"awake", "brainwt", "bodywt"),
313-
selected = "sleep_total"),
314-
tabsetPanel(id = "vore",
315-
tabPanel("Carnivore",
316-
plotOutput("plot_carni")),
317-
tabPanel("Omnivore",
318-
plotOutput("plot_omni")),
319-
tabPanel("Herbivore",
320-
plotOutput("plot_herbi")))
321-
)
322-
323-
server <- function(input, output, session) {
324-
325-
# make subsets
326-
carni <- reactive( filter(msleep, vore == "carni") )
327-
omni <- reactive( filter(msleep, vore == "omni") )
328-
herbi <- reactive( filter(msleep, vore == "herbi") )
329-
330-
# make plots
331-
output$plot_carni <- renderPlot({
332-
ggplot(data = carni(), aes_string(x = input$x, y = input$y)) +
333-
geom_point()
334-
}, res = 96)
335-
output$plot_omni <- renderPlot({
336-
ggplot(data = omni(), aes_string(x = input$x, y = input$y)) +
337-
geom_point()
338-
}, res = 96)
339-
output$plot_herbi <- renderPlot({
340-
ggplot(data = herbi(), aes_string(x = input$x, y = input$y)) +
341-
geom_point()
342-
}, res = 96)
343-
344-
}
345-
346-
shinyApp(ui = ui, server = server)
347-
```
348-
349-
2. Continue working with the same app from the previous exercise, and further remove redundancy in the code by modularizing how subsets and plots are created.
350-
351-
3. Suppose you have an app that is slow to launch when a user visits it.
352-
Can\
353-
modularizing your app code help solve this problem?
354-
Explain your reasoning.
355-
356295
## Summary
357296

358297
As your apps get bigger, extracting non-reactive functions out of the flow of the app will make your life substantially easier.

0 commit comments

Comments
 (0)