Flexdashboard Demo"

library(tidyverse)
library(shiny)        #renderPlot, renderTable, sliderInput
library(shinyWidgets) #radioGroupButtons
get_data <- mpg 

MPG Example

Column {.sidebar data-width=200}

Filter the data:

#You can make this sidebar global by putting it ahead of Tab 1
#below are 2 input options: a gorup of buttons, and a slider
radioGroupButtons(#for categorical variables
    inputId = "year", #this will allow the selection to be referenced as input$cyl
    label = "Select Year of Vehicle", #NULL if you don't want a header
    choiceNames = c("All", sort(unique(get_data$year))), #can use paste, etc to make nicer display
    choiceValues = c("All", sort(unique(get_data$year))), #values in the data, need to line up with above
    justified =  T, #will fill the width of the container it sits in (sidebar) 
    status = "primary")
sliderInput(
    inputId = "displ", #referenced as input$displ
    label = "Select Weight:",
    value = range(get_data$displ), #default selection, you can move the range around
    min = (min(get_data$displ)),
    max = (max(get_data$displ)),
    step = .1)
#This will build a dataframe to use throughout the dashboard. To reference this dataframe, you will need to be in some reactive element ex: renderText({nrow(use_data())}). This is essentially a function and so you will need to use parentheses at the end like this: use_data() 

Column {data-width=450}

Highway MPG by Engine Displacement

renderPlot({ #renderPlot is only required becuase we are referencing someting reactive: use_data(). Otherwise we could just use ggplot(get_data,...)
    ggplot(get_data, aes(displ, hwy)) +
        geom_smooth(color = "grey65") +
        geom_point(aes(color = factor(cyl))) +
        ylim(0, 45) +
        labs(color = "Cylinder") +
        theme(legend.position = "bottom")
})


Try the shinyobjects package in your browser

Any scripts or data that you put into this service are public.

shinyobjects documentation built on July 29, 2020, 9:07 a.m.