Exercise
- Take your own data.
- Use the code below.
- Built a simple app that let’s the user select variables in your dataset and plot them.
- Think of possible extensions to the app.
# THIS CREATES THE USER INTERFACE
ui <- fluidPage(
titlePanel("My first shiny app :-)"),
sidebarLayout(
sidebarPanel(
selectInput("selection", label = h3("Select box"),
choices = list("Fertility" = "Fertility",
"Agriculture" = "Agriculture",
"Catholic" = "Catholic"),
selected = 1)
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- swiss[, input$selection]
hist(x, col = 'darkgray', border = 'white', xlab=input$selection,
main="Swiss French Provinces Fertility and Socioeconomic Indicators (1888) Data")
})
}
shinyApp(ui = ui, server = server)
# THIS CREATES THE USER INTERFACE
ui <- fluidPage(
titlePanel("My first shiny app :-)"),
sidebarLayout(
sidebarPanel(
selectInput("selection", label = h3("Select box"),
choices = list("Examination" = "Examination",
"Agriculture" = "Agriculture",
"Catholic" = "Catholic",
"Education" = "Education",
"Infant.Mortality" = "Infant.Mortality"),
selected = 1)
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
#hist(x, col = 'darkgray', border = 'white', xlab=input$selection,
main="Swiss French Provinces Fertility and Socioeconomic Indicators (1888) Data")
ggplot(data = swiss,
y = Fertility,
x = input$selection) %>% geom_point()
})
}
shinyApp(ui = ui, server = server)