Skip to content

Instantly share code, notes, and snippets.

@jtleek
Created March 13, 2019 17:50
Show Gist options
  • Save jtleek/3e1baac9a74ea81556c9e6d55743d7ea to your computer and use it in GitHub Desktop.
Save jtleek/3e1baac9a74ea81556c9e6d55743d7ea to your computer and use it in GitHub Desktop.
Example interactive app in R
---
title: "How does your BMI measure up?"
output: flexdashboard::flex_dashboard
runtime: shiny
---
Inputs {.sidebar}
-------------------------------------
```{r}
library(flexdashboard); library(NHANES); library(plotly);library(dplyr)
sliderInput("height", "Height in inches",0,100,72)
sliderInput("weight", "Weight in pounds",0,500,100)
sliderInput("age", "Age in years",0,120,50)
```
Column
-------------------------------------
### Chart 1
```{r}
nhanes = sample_n(NHANES,100)
renderPlotly({
df = data.frame(bmi = c(nhanes$BMI,input$weight*0.45/(input$height*0.025)^2),
age = c(nhanes$Age,input$age),
who = c(rep("nhanes",100),"you"))
ggplotly(ggplot(df) +
geom_point(aes(x=age,y=bmi,color=who)) +
scale_x_continuous(limits=c(0,90)) +
scale_y_continuous(limits=c(0,60)) +
theme_minimal()
)
})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment