+ - 0:00:00
Notes for current slide
Notes for next slide

Visualizing openFDA data with R, plotly, and dashR

Carson Sievert, PhD
CEO, Sievert Consulting LLC

Slides: https://talks.cpsievert.me

@cpsievert
@cpsievert
https://cpsievert.me/
cpsievert1@gmail.com

Slides released under Creative Commons

1 / 32

dash: a python framework for reactive web apps

dash is a product of plotly

2 / 32

MIT licensed: built on flask & react

Paid services (e.g. private cloud, on-premise, etc)

3 / 32

dashR: an R framework for reactive web apps

dashR is not yet released...

4 / 32

But R already has shiny...why bother with dashR?

5 / 32

Reason 1: Agile development

Easily switch between R/Python backend

6 / 32

A dashR template:

library(dashR)
app = Dash$new()
app$layout_set(
# defines the layout/UI
# (a collection of "components")
)
app$callback(
# maps input(s) -> output
)
app$run_server()

Can have multiple callbacks, but only one layout

7 / 32

A simple dashR app:

library(dashR)
app = Dash$new()
app$layout_set(
coreInput(
id = 'a',
value = 'Hello World!',
type = "text"
),
htmlDiv(id = 'b')
)
app$callback(
function(text = input("a")) {
paste("You entered:", text)
},
output("b")
)
app$run_server()

8 / 32

dashR version

library(dashR)
app = Dash$new()
app$layout_set(
coreInput(
id = 'a',
value = 'Hello World!',
type = "text"
),
htmlDiv(id = 'b')
)
app$callback(
function(text = input("a")) {
paste("You entered:", text)
},
output("b")
)
app$run_server()

dash (python) version

import dash
import dash_core_components as core
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
core.Input(
id = 'a',
value = 'Hello World!',
type = "text"
),
html.Div(id = 'b')
])
@app.callback(
Output('b', 'children'),
[Input('a', 'value')]
)
def update(text):
return "You entered: " + text
app.run_server()
9 / 32

Reason 2: stateless web architecture

10 / 32

When is stateless useful?

  • Scaling apps to many concurrent users (or requests).

What does stateless mean?

  • A stateless server treats each request as an independent transaction that is unrelated to any previous request.

How does dashR manage to be stateless?

  • dash/dashR's dependency graph is managed on the client via dash-renderer

    • When a callback needs to be executed, the client makes an HTTP request to an R server.

    • As long as callback functions do not create side-effects, requests can be managed in a stateless fashion

11 / 32

Reason 3: leverage the dash & react communities

12 / 32


13 / 32

Visualizing openFDA data

Example 1: Visualizing adverse drug outcomes

Example 2: Visualizing drug recall enforcements

14 / 32

First, let's survey some existing work

15 / 32

What about comparing drug outcomes?

17 / 32

What about comparing many drugs?

19 / 32

Same data, different look

20 / 32

Heatmap of 1000 drug outcomes (made with heatmaply and plotly)

Interactive

21 / 32

What about comparing millions of drugs?

22 / 32

Overview first, then zoom and filter, then details on demand

Dr. Ben Shneiderman

In other words, show summary stats first, then guided exploration to raw data.

23 / 32

Using principal components and interactive graphics to identify then examine 'unusual' patterns.

24 / 32

Visualizing openFDA data

Example 1: Visualizing adverse drug outcomes

Example 2: Visualizing drug recall enforcements

25 / 32
26 / 32

If we have time, here are some more dash/dashR apps.

NOTE: I did not create the following apps.

27 / 32
28 / 32
29 / 32
30 / 32

In summary

  • dash is a Python framework for creating reactive web apps.

  • dashR is an R framework for creating reactive web apps.

  • dash/dashR is appealing because:

    • Choose between R or Python backend

    • Stateless web architecture

    • Reusable components

  • However, note that:

31 / 32

dash: a python framework for reactive web apps

dash is a product of plotly

2 / 32
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow