CommencerCommencer gratuitement

Alien sightings: add outputs

Now that the dashboard has inputs, you should build your outputs to actually see information about the reported UFO sightings.

Recall there will be two, a plot and a table. The plot should show the number sighted, by shape, for the selected state and time period. The table should show, for the selected state and time period, the number sighted, plus the average, median, minimum, and maximum duration (duration_sec) of the sightings. This will require using dplyr, or a method of your choosing, to manipulate the usa_ufo_sightings data.

Cet exercice fait partie du cours

Building Web Applications with Shiny in R

Afficher le cours

Instructions

  • Add a bar plot output named 'shapes', showing the number of UFOs sighted, by shape, for the selected state and time period.

    Make sure to create the output in the server, and also display it in the UI.

  • Add a table output showing named 'duration_table', by shape, the number of UFOs sighted, plus the average, median, minimum, and maximum duration of the sightings. Note that the table should only show data for the selected state and time period.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

ui <- fluidPage(
  titlePanel("UFO Sightings"),
  sidebarLayout(
    sidebarPanel(
      selectInput("state", "Choose a U.S. state:", choices = unique(usa_ufo_sightings$state)),
      dateRangeInput("dates", "Choose a date range:",
                     start = "1920-01-01",
                     end = "1950-01-01")
    ),
    mainPanel(
      # Add plot output named 'shapes'

      # Add table output named 'duration_table'

    )
  )
)

server <- function(input, output) {
  # CODE BELOW: Create a plot output of sightings by shape,
  # For the selected inputs

  
  
  
  
  # CODE BELOW: Create a table output named 'duration_table', by shape,
  # of # sighted, plus mean, median, max, and min duration of sightings
  # for the selected inputs

  
  
}

shinyApp(ui, server)
Modifier et exécuter le code