Dump" videos on YouTube: http://bit.ly/shinybraindump • Generating HTML • Customizing with CSS • Validation • Web Application Development with R Using Shiny by Chris Beeley • Shiny Cheat Sheet: http://shiny.rstudio.com/articles/cheatsheet.html
debugging tools? • browser() drops you into running code • RStudio makes browse prompts easier to work with • options(error=browser) automatically invokes browser() when "top-level" errors occur
encounter? 1. App fails to load or run 2. Error message where an output is expected 3. An error causes the app to exit 4. Unexpected behavior (or lack of behavior)
• One missing or misplaced comma in ui.R will stop the app from loading • "argument is missing, with no default" means extra comma • "unexpected symbol" means missing comma • "Operation not allowed without an active reactive context": trying to run something once that needs to run (potentially) many times
expected • An error is occurring somewhere in the chain of execution for calculating an output • Use options(shiny.error = browser) and the RStudio call stack viewer to identify the misbehaving piece of code • If more investigation is needed, add an explicit browser() call to the offending piece of code, and use RStudio to step through
exit • If the web page background goes grey but the R console hasn't returned, it's just that session that exited • Good chance that an error is being raised in an observe() • Use options(shiny.observer.error = function(e, label, domain) { browser() }) to narrow down (ugh... sorry) • If error is expected, use a tryCatch in the observer
• Look at both the R console and your browser's JavaScript error console • Inspect websocket messages using options(shiny.trace = TRUE) and Chrome Web Inspector's Network panel (look for the websocket) • Try the reactivity visualizer tool (?showReactLog)
asked. • Shiny has always supported custom inputs/outputs http://shiny.rstudio.com/articles/building-inputs.html http://shiny.rstudio.com/articles/building-outputs.html • Requires fluency in JavaScript • Easy to get wrong—low "pit of success" factor
package that contains (at a minimum): • JavaScript library dependencies, under inst/htmlwidgets (easy!) • R functions for constructing the widget (easy!) • JavaScript binding code (...less easy) • Initializes the JavaScript widget—once per element • Renders data on the widget—potentially many times • Resizes the widget as window size changes
values (including input) • Reactive expressions: reactive({...}) • Observers: observe({...}) • Q: Where are outputs? A: They're not primitives— composed of observers and reactive expressions
not execute until the first time it is read. Once invalidated, it does not re-execute until the next time it is read. • observe(): eager • Observers execute automatically immediately(- ish) after they are created, and re-execute automatically whenever they are invalidated
to the system that's visible outside of a function, besides its return value. E.g. writing a file to disk, modifying an object in the global environment or parent scope. • reactive(): As a general rule, user logic should not cause side effects; the only effect of reading the reactive should be a value being returned. Pure functional paradigm. • observe(): Useful only for side effects. Imperative paradigm.
observers in reactives—almost never correct. # Bad! a <- reactive({ b <- reactive(...) ... }) • (Observers in observers can be OK though.) • Using <<- to assign variables in reactives and reading them from renderXXX functions. Instead, use whatever values are interesting as the reactive's return value.