dtkaplan / shinymark

Files for the RStudio::conf 2019 workshop: Introduction to Shiny and R Markdown
48 stars 23 forks source link

Shiny reactivity: add slide introducing what is reactivity #4

Open daattali opened 5 years ago

daattali commented 5 years ago

I think that before jumping into what the input$ list is, it's a good idea to quickly define what reactivity is and show a small example. This could help make the rest of the concept a bit clearer to people who have never heard of this before.

I suggest making the first slide in lesson 5 as follows:


Reactivity 101

x <- 5
y <- x + 1
x <- 10
# What is y? 6 or 11?

Show this slide, talk about how in R we are used to thinking that in this code, when x changes y is unaffected. Then say that if x and y are reactive variables, then y reacts to x changing and gets updated as well, so in a reactive world, such as shiny, y would now be 11. This is what reactivity means in a very broad simplification.

If you don't like this idea, feel free to ignore :)

dtkaplan commented 5 years ago

Yes, a good idea. Thanks. I've expanded it a bit in the 05 slides, making it part of an analogy to the difference between the muggle world (in Harry Potter) and the wizard world.

daattali commented 5 years ago

I like it! Nice analogy.

I'm not sure about the "shinyApp() turns UI into a reactive value" - unless I'm misunderstanding what you mean? The UI is typically defined as ui <- fluidPage(...) and it just returns static HTML code, it's not reactive in any way that I can think of

dtkaplan commented 5 years ago

Right. But when you invoke shinyApp( ) it scans the UI and creates the reactive value called input, with a field for each of the controls.

On Mon, Jan 14, 2019 at 10:28 AM Dean Attali notifications@github.com wrote:

I like it! Nice analogy.

I'm not sure about the "shinyApp() turns UI into a reactive value" - unless I'm misunderstanding what you mean? The UI is typically defined as ui <- fluidPage(...) and it just returns static HTML code, it's not reactive in any way that I can think of

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dtkaplan/shinymark/issues/4#issuecomment-454067628, or mute the thread https://github.com/notifications/unsubscribe-auth/AAggrSvvruF3Atz2surZehkVkBgo-foHks5vDLAOgaJpZM4Z755T .

--

...

DeWitt Wallace Professor of Mathematics, Statistics, and Computer Science Macalester College