外星人目击:添加输出
现在仪表板已有输入,您需要构建输出,实际查看报告的 UFO 目击信息。
回顾一下会有两个输出:一个图和一张表。该图应在所选州和时间范围内,按形状展示目击数量。该表应在所选州和时间范围内,按形状展示目击数量,以及目击时长(duration_sec)的平均值、中位数、最小值和最大值。为此,您需要使用 dplyr(或您选择的其他方法)来处理 usa_ufo_sightings 数据。
本练习是课程的一部分
使用 R 构建 Shiny Web 应用
练习说明
添加名为
'shapes'的柱状图输出,在所选州和时间范围内,按形状显示 UFO 的目击数量。请确保在 server 中创建该输出,并在 UI 中显示。
添加名为
'duration_table'的表格输出,按形状显示 UFO 的目击数量,以及目击时长的平均值、中位数、最小值和最大值。请注意,该表只应显示所选州和时间范围内的数据。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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)