闪亮的应用程序问题;空白输出;没有错误信息
Issues with shiny app; Blank output; No error message
我一直在尝试创建一个简单的闪亮应用程序。我正在使用的数据是 .xlsx 格式的机场每日航班和乘客数量的数据框,日期列为 yyyy-mm-dd 格式,还有一个日期列、月份列和年份。我希望能够 select 一个日期范围并接收相应的图,其中 x=date(输入日期范围)和 y=flights。
这里是 head():
# A tibble: 6 × 7
date passengers flights pas_per_flight month day year
<dttm> <dbl> <dbl> <dbl> <chr> <chr> <chr>
1 2019-01-01 00:00:00 75505 563 134. 1 1 2019
2 2019-01-02 00:00:00 92393 659 140. 1 2 2019
3 2019-01-03 00:00:00 81189 627 129. 1 3 2019
4 2019-01-04 00:00:00 83156 658 126. 1 4 2019
5 2019-01-05 00:00:00 78043 560 139. 1 5 2019
6 2019-01-06 00:00:00 87890 655 134. 1 6 2019
这里是 dput(head())
structure(list(date = structure(c(1546300800, 1546387200, 1546473600,
1546560000, 1546646400, 1546732800), tzone = "UTC", class = c("POSIXct",
"POSIXt")), passengers = c(75505, 92393, 81189, 83156, 78043,
87890), flights = c(563, 659, 627, 658, 560, 655), pas_per_flight = c(134.11190053286,
140.201820940819, 129.488038277512, 126.376899696049, 139.3625,
134.18320610687), month = c("1", "1", "1", "1", "1", "1"), day = c("1",
"2", "3", "4", "5", "6"), year = c("2019", "2019", "2019", "2019",
"2019", "2019")), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
这是我想到的,但不幸的是我没有要报告的错误消息。该应用程序运行,日期范围 select 或在那里并且正在运行,但没有任何情节被推出。应用程序的“中心”保持空白。
library(shiny)
library(dplyr)
library(ggplot2)
library(readxl)
zhairport<-read_xlsx("airport.xlsx")
ui <- fluidPage(
sidebarLayout(
mainPanel(plotOutput("date")),
sidebarPanel(
dateRangeInput("date", "Choose timeframe", start="2019-01-01", end="2020-12-31",
min="2019-01-01",max="2020-12-31"),
)),
)
server<-function(input, output, session){
subdata<-reactive({
zhairport %>%
filter(
as.Date(date) >= as.Date(input$date[1]),
as.Date(date) <= as.Date(input$date[2]),
)
})
output$plot<-renderPlot({
ggplot(subdata(),
aes(x=date, y=flights)
+geom_line(aes(x=date,y=flights)))
})
}
shinyApp(ui = ui, server = server)
对于可怕的格式和可能非常糟糕的代码表示歉意,这是我的第一个应用程序。
TIA 任何答案!
这里是更正后的代码
zhairport <-structure(list(date = structure(c(1546300800, 1546387200, 1546473600,
1546560000, 1546646400, 1546732800), tzone = "UTC", class = c("POSIXct", "POSIXt")), passengers = c(75505, 92393, 81189, 83156, 78043,87890), flights = c(563, 659, 627, 658, 560, 655), pas_per_flight = c(134.11190053286,140.201820940819, 129.488038277512, 126.376899696049, 139.3625,134.18320610687), month = c("1", "1", "1", "1", "1", "1"), day = c("1","2", "3", "4", "5", "6"), year = c("2019", "2019", "2019", "2019","2019", "2019")), row.names = c(NA, -6L), class = c("tbl_df","tbl", "data.frame"))
library(shiny)
library(dplyr)
library(ggplot2)
library(readxl)
ui <- fluidPage(
sidebarLayout(
mainPanel(plotOutput("plot")),
sidebarPanel(
dateRangeInput("date", "Choose timeframe", start="2019-01-01", end="2020-12-31",
min="2019-01-01",max="2020-12-31"),
)),
)
server<-function(input, output, session){
subdata<-reactive({
zhairport %>%
filter(
as.Date(date) >= as.Date(input$date[1]),
as.Date(date) <= as.Date(input$date[2]),
)
})
output$plot<-renderPlot({
data = subdata()
ggplot(data,
aes(x=date, y=flights)) +geom_line(aes(x=date,y=flights))
})
}
shinyApp(ui = ui, server = server)
我一直在尝试创建一个简单的闪亮应用程序。我正在使用的数据是 .xlsx 格式的机场每日航班和乘客数量的数据框,日期列为 yyyy-mm-dd 格式,还有一个日期列、月份列和年份。我希望能够 select 一个日期范围并接收相应的图,其中 x=date(输入日期范围)和 y=flights。
这里是 head():
# A tibble: 6 × 7
date passengers flights pas_per_flight month day year
<dttm> <dbl> <dbl> <dbl> <chr> <chr> <chr>
1 2019-01-01 00:00:00 75505 563 134. 1 1 2019
2 2019-01-02 00:00:00 92393 659 140. 1 2 2019
3 2019-01-03 00:00:00 81189 627 129. 1 3 2019
4 2019-01-04 00:00:00 83156 658 126. 1 4 2019
5 2019-01-05 00:00:00 78043 560 139. 1 5 2019
6 2019-01-06 00:00:00 87890 655 134. 1 6 2019
这里是 dput(head())
structure(list(date = structure(c(1546300800, 1546387200, 1546473600,
1546560000, 1546646400, 1546732800), tzone = "UTC", class = c("POSIXct",
"POSIXt")), passengers = c(75505, 92393, 81189, 83156, 78043,
87890), flights = c(563, 659, 627, 658, 560, 655), pas_per_flight = c(134.11190053286,
140.201820940819, 129.488038277512, 126.376899696049, 139.3625,
134.18320610687), month = c("1", "1", "1", "1", "1", "1"), day = c("1",
"2", "3", "4", "5", "6"), year = c("2019", "2019", "2019", "2019",
"2019", "2019")), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
这是我想到的,但不幸的是我没有要报告的错误消息。该应用程序运行,日期范围 select 或在那里并且正在运行,但没有任何情节被推出。应用程序的“中心”保持空白。
library(shiny)
library(dplyr)
library(ggplot2)
library(readxl)
zhairport<-read_xlsx("airport.xlsx")
ui <- fluidPage(
sidebarLayout(
mainPanel(plotOutput("date")),
sidebarPanel(
dateRangeInput("date", "Choose timeframe", start="2019-01-01", end="2020-12-31",
min="2019-01-01",max="2020-12-31"),
)),
)
server<-function(input, output, session){
subdata<-reactive({
zhairport %>%
filter(
as.Date(date) >= as.Date(input$date[1]),
as.Date(date) <= as.Date(input$date[2]),
)
})
output$plot<-renderPlot({
ggplot(subdata(),
aes(x=date, y=flights)
+geom_line(aes(x=date,y=flights)))
})
}
shinyApp(ui = ui, server = server)
对于可怕的格式和可能非常糟糕的代码表示歉意,这是我的第一个应用程序。
TIA 任何答案!
这里是更正后的代码
zhairport <-structure(list(date = structure(c(1546300800, 1546387200, 1546473600,
1546560000, 1546646400, 1546732800), tzone = "UTC", class = c("POSIXct", "POSIXt")), passengers = c(75505, 92393, 81189, 83156, 78043,87890), flights = c(563, 659, 627, 658, 560, 655), pas_per_flight = c(134.11190053286,140.201820940819, 129.488038277512, 126.376899696049, 139.3625,134.18320610687), month = c("1", "1", "1", "1", "1", "1"), day = c("1","2", "3", "4", "5", "6"), year = c("2019", "2019", "2019", "2019","2019", "2019")), row.names = c(NA, -6L), class = c("tbl_df","tbl", "data.frame"))
library(shiny)
library(dplyr)
library(ggplot2)
library(readxl)
ui <- fluidPage(
sidebarLayout(
mainPanel(plotOutput("plot")),
sidebarPanel(
dateRangeInput("date", "Choose timeframe", start="2019-01-01", end="2020-12-31",
min="2019-01-01",max="2020-12-31"),
)),
)
server<-function(input, output, session){
subdata<-reactive({
zhairport %>%
filter(
as.Date(date) >= as.Date(input$date[1]),
as.Date(date) <= as.Date(input$date[2]),
)
})
output$plot<-renderPlot({
data = subdata()
ggplot(data,
aes(x=date, y=flights)) +geom_line(aes(x=date,y=flights))
})
}
shinyApp(ui = ui, server = server)