Created
March 13, 2019 17:50
-
-
Save jtleek/3e1baac9a74ea81556c9e6d55743d7ea to your computer and use it in GitHub Desktop.
Example interactive app in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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