That way whenever the user makes a change, an update will follow within a few microseconds. Instead of watching the user (which would require logistics we haven’t thought through), you could just have your server re-run each expression in the app every few microseconds. This suggests a new feature for our plan. You could actually let a few microseconds pass between change and update and your user wouldn’t notice. REACTIVITY WINDOWSHowever, humans aren’t very good at noticing small windows of time. In other words, the update will create the illusion of reactivity. How quickly do you need to re-run an expression after a user makes a change? If the update appears instantaneous, the user will feel like they caused it. All you need to do is manually re-run the expressions in the app whenever the user makes a change. You could use this behavior – and nothing else – to create a reactive web app. In other words, R will not execute an expression until you force it to. However, you must tell R to run the expresssion for this to happen because R uses a style of execution known as lazy evaluation. It looks up the current value of each object that it uses and computes new ouput. Think of it like this: every time you run an expression, the expression updates itself. a <- 1 print ( a ) # 1 a <- 2 print ( a ) # 2 This isn’t reactivity it’s just standard R behavior. Everything in R updates itself each time it is run. Updating an out of date expression is not hard: you just need to re-run the expression. For example, at the end of this code, the expression print(a) is out of date. Reactivity ensures that the output of print(input$a) is always up to date, but what does it mean for output to be out of date? Let’s consider output – and the expression that made it – to be out of date if one of the objects in the expression has been given a new value since the expression was called. R expressions update themselves, if you ask
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |