You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scaling-functions.Rmd
-61Lines changed: 0 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -292,67 +292,6 @@ server <- function(input, output, session) {
292
292
293
293
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.
294
294
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.
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
-
356
295
## Summary
357
296
358
297
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