Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.