开始使用免费开始使用

Explore the Mental Health in Tech 2014 Survey

Don't be intimidated, but in this exercise, you're going to build the entirety of this app (minus the custom error message) in one go!

For this app, you'll be using the questions "Do you think that discussing a mental health issue with your employer would have negative consequences?" (the mental_health_consequence variable) and "Do you feel that your employer takes mental health as seriously as physical health?" (mental_vs_physical) as multi-selector inputs, then displaying a histogram of the Age of respondents. To see the choices for these variables, count() them in the console.

Recall that when you're finished, the app will look like this (including the blank plot): An app displaying questions from a Mental Health survey

shiny, ggplot2, dplyr, and the mental_health_survey dataset have all been loaded for you.

本练习是课程的一部分

Building Web Applications with Shiny in R

查看课程

练习说明

  • UI:
    • Add an appropriate title to the app.
    • Add a checkboxGroupInput(). Include a default value for the selected argument.
    • Add a pickerInput() with the multiple argument set to TRUE.
    • Add a plotOutput() in the main panel.
  • Server:
    • Add an output that displays a histogram the Age of respondents, filtered by the two inputs.

交互式实操练习

通过完成这段示例代码来试试这个练习。

ui <- fluidPage(
  # CODE BELOW: Add an appropriate title

  sidebarPanel(
  	# CODE BELOW: Add a checkboxGroupInput

    
    
    
    

  	# CODE BELOW: Add a pickerInput

    
    
    
    
    
  ),
  mainPanel(
	# CODE BELOW: Display the output

  )
)

server <- function(input, output, session) {
  # CODE BELOW: Build a histogram of the age of respondents
  # Filtered by the two inputs

  
  
  
  
  
  
  
}

shinyApp(ui, server)
编辑并运行代码