未找到对象 'output' 的 ShinyApp 问题
ShinyApp Issue with object 'output' not found
我在 shiny 应用程序中调试时遇到了一些问题。我添加了一些新东西后它不起作用,但它仍然能够打开闪亮的应用程序平台,尽管有些内容是空白的并有错误消息。 table 和散点图对我不起作用。以下是不断出现的错误。
输出错误$[=27=] <- renderDataTable(trend_data()) :
找不到对象 'output'"
找不到函数"y"
我不知道如何使 table 和绘图工作。
# shape <- st_read("tl_2016_53_cousub.shp")
# sta <- read_csv("NOAA_SeattlePortageBay.csv") %>% #weather station
# mutate(lon = Longitude, lat = Latitude) %>%
# st_as_sf(coords = c("LONGITUDE", "LATITUDE"), crs=4326) %>%
# st_join(shape)
trend_data <- read_csv("NOAA_SeattlePortageBay.csv")
y <- trend_data %>%
sample_n(0) %>%
select("Total Liquid Content", "Extreme Max Precip", "Annual Mean Temp", "Mean Max Temp", "Mean Min Temp")
ui <- fluidPage(title = "Seattle, Washington 40 Years Climate",
navlistPanel(
tabPanel(title = "Introduction",
leafletOutput("map"),
textOutput("dis")),
tabPanel(title = "Climate Graphs",
plotOutput("plot1"),
# plotOutput("plot2"),
plotOutput("plot3"),
plotOutput("plot4"),
plotOutput("plot5")),
tabPanel(title = "Data Table",
tableOutput("table")),
tabPanel(title = "Plot Model",
plotOutput("scatterplot"),
varSelectInput("yvar", "Y Variable:", data=y, selected="Total Liquid Content"))
)
)
server <- function(input, output) {
# output$map <- renderLeaflet({ #doesn't work so I use another route
# leaflet(data = sta) %>%
# addTiles() %>%
# addMarkers(~lon, ~lat, label = ~Name)
# output$dis <- renderText("Seattle is a city located in the State of Washington.
# Seattle Portage Bay Weather Station by NOAA.")
output$map <- renderLeaflet({
leaf <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=-122.3, lat= 47.65,
popup="Seattle Portage Bay, WA, USA, GHCND:USW00024281")
})
output$dis <- renderText("Seattle Portage Bay Weather Station by NOAA.","\r",
"Elevatioin: 5.8m", "\r",
"Period of Record: January 1, 1894 to January 1, 1997")
output$plot1 <- renderPlot({ #Error in output$plot1 <- renderPlot({ : object 'output' not found
ggplot(trend_data) + #unexpected '}' in "}"
geom_point(aes(Year, trend_data$`Total Liquid Content`),
size = 3, color = "dark blue") +
geom_smooth(aes(Year, trend_data$`Total Liquid Content`), size = 1, color = "black", method = "lm") +
labs(title = "Total Precipitation",
x = "Year", y = "Precipitation in Inches") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(15, 55) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
# output$plot2 <- renderPlot({
# ggplot(trend_data) +
# geom_point(aes(Year, trend_data$`Extreme Max Precip`),
# size = 3, color = "red") +
# geom_smooth(aes(Year, trend_data$`Extreme Max Precip`), size = 1, color = "black", method = "lm") +
# labs(title = "Extreme Max Precipitation",
# x = "Year", y = "Precipitation in Inches") +
# theme(text= element_text(size=15, family="Arial"),
# plot.title = element_text(hjust = 0.5)) + ylim(15, 55) +
# scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
# })
output$plot3 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, trend_data$`Annual Mean Temp`),
size = 3, color = "brown") +
geom_smooth(aes(Year, trend_data$`Annual Mean Temp`), size = 1, color = "black", method = "lm") +
labs(title = "Average Temperature",
x = "Year", y = "Temperature in Fahrenheit") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(50, 56) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
output$plot4 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, trend_data$`Mean Max Temp`),
size = 3, color = "red") +
geom_smooth(aes(Year, trend_data$`Mean Max Temp`), size = 1, color = "black", method = "lm") +
labs(title = "Average Maximum Temperature",
x = "Year", y = "Temperature in Fahrenheit") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(57, 64) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
output$plot5 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, trend_data$`Mean Min Temp`),
size = 3, color = "light blue") +
geom_smooth(aes(Year, trend_data$`Mean Min Temp`), size = 1, color = "black", method = "lm") +
labs(title = "Average Minimum Temperature",
x = "Year", y = "Temperature in Fahrenheit") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(43, 50) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
output$table <- renderDataTable(trend_data())
output$scatterplot <- renderPlot({
ggplot(data = y()) + #can't find function y
geom_point(mapping = aes(x = Year, y = !!input$yvar)) +
geom_smooth(mapping = aes(x = Year, y = !!input$yvar), method="lm")
})
}
shinyApp(ui = ui, server = server)
output$table <- renderDataTable(trend_data())
在上面的代码中,您的 trend_data
不是反应性数据集。
你可以
制作 trend_data
一个反应性数据集,它会根据您的 Shiny App 中的一些反应性而改变。
trend_data <- reactive({
#some code here
})
或者直接使用trend_data
output$table <- renderDataTable(trend_data)
并在 plot1 错误中删除 trend_data$
output$plot1 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, `Total Liquid Content`),
size = 3, color = "dark blue") +
geom_smooth(aes(Year, `Total Liquid Content`), size = 1, color = "black", method = "lm") +
labs(title = "Total Precipitation",
x = "Year", y = "Precipitation in Inches") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(15, 55) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
我在 shiny 应用程序中调试时遇到了一些问题。我添加了一些新东西后它不起作用,但它仍然能够打开闪亮的应用程序平台,尽管有些内容是空白的并有错误消息。 table 和散点图对我不起作用。以下是不断出现的错误。
输出错误$[=27=] <- renderDataTable(trend_data()) : 找不到对象 'output'"
找不到函数"y"
我不知道如何使 table 和绘图工作。
# shape <- st_read("tl_2016_53_cousub.shp")
# sta <- read_csv("NOAA_SeattlePortageBay.csv") %>% #weather station
# mutate(lon = Longitude, lat = Latitude) %>%
# st_as_sf(coords = c("LONGITUDE", "LATITUDE"), crs=4326) %>%
# st_join(shape)
trend_data <- read_csv("NOAA_SeattlePortageBay.csv")
y <- trend_data %>%
sample_n(0) %>%
select("Total Liquid Content", "Extreme Max Precip", "Annual Mean Temp", "Mean Max Temp", "Mean Min Temp")
ui <- fluidPage(title = "Seattle, Washington 40 Years Climate",
navlistPanel(
tabPanel(title = "Introduction",
leafletOutput("map"),
textOutput("dis")),
tabPanel(title = "Climate Graphs",
plotOutput("plot1"),
# plotOutput("plot2"),
plotOutput("plot3"),
plotOutput("plot4"),
plotOutput("plot5")),
tabPanel(title = "Data Table",
tableOutput("table")),
tabPanel(title = "Plot Model",
plotOutput("scatterplot"),
varSelectInput("yvar", "Y Variable:", data=y, selected="Total Liquid Content"))
)
)
server <- function(input, output) {
# output$map <- renderLeaflet({ #doesn't work so I use another route
# leaflet(data = sta) %>%
# addTiles() %>%
# addMarkers(~lon, ~lat, label = ~Name)
# output$dis <- renderText("Seattle is a city located in the State of Washington.
# Seattle Portage Bay Weather Station by NOAA.")
output$map <- renderLeaflet({
leaf <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=-122.3, lat= 47.65,
popup="Seattle Portage Bay, WA, USA, GHCND:USW00024281")
})
output$dis <- renderText("Seattle Portage Bay Weather Station by NOAA.","\r",
"Elevatioin: 5.8m", "\r",
"Period of Record: January 1, 1894 to January 1, 1997")
output$plot1 <- renderPlot({ #Error in output$plot1 <- renderPlot({ : object 'output' not found
ggplot(trend_data) + #unexpected '}' in "}"
geom_point(aes(Year, trend_data$`Total Liquid Content`),
size = 3, color = "dark blue") +
geom_smooth(aes(Year, trend_data$`Total Liquid Content`), size = 1, color = "black", method = "lm") +
labs(title = "Total Precipitation",
x = "Year", y = "Precipitation in Inches") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(15, 55) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
# output$plot2 <- renderPlot({
# ggplot(trend_data) +
# geom_point(aes(Year, trend_data$`Extreme Max Precip`),
# size = 3, color = "red") +
# geom_smooth(aes(Year, trend_data$`Extreme Max Precip`), size = 1, color = "black", method = "lm") +
# labs(title = "Extreme Max Precipitation",
# x = "Year", y = "Precipitation in Inches") +
# theme(text= element_text(size=15, family="Arial"),
# plot.title = element_text(hjust = 0.5)) + ylim(15, 55) +
# scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
# })
output$plot3 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, trend_data$`Annual Mean Temp`),
size = 3, color = "brown") +
geom_smooth(aes(Year, trend_data$`Annual Mean Temp`), size = 1, color = "black", method = "lm") +
labs(title = "Average Temperature",
x = "Year", y = "Temperature in Fahrenheit") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(50, 56) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
output$plot4 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, trend_data$`Mean Max Temp`),
size = 3, color = "red") +
geom_smooth(aes(Year, trend_data$`Mean Max Temp`), size = 1, color = "black", method = "lm") +
labs(title = "Average Maximum Temperature",
x = "Year", y = "Temperature in Fahrenheit") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(57, 64) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
output$plot5 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, trend_data$`Mean Min Temp`),
size = 3, color = "light blue") +
geom_smooth(aes(Year, trend_data$`Mean Min Temp`), size = 1, color = "black", method = "lm") +
labs(title = "Average Minimum Temperature",
x = "Year", y = "Temperature in Fahrenheit") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(43, 50) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})
output$table <- renderDataTable(trend_data())
output$scatterplot <- renderPlot({
ggplot(data = y()) + #can't find function y
geom_point(mapping = aes(x = Year, y = !!input$yvar)) +
geom_smooth(mapping = aes(x = Year, y = !!input$yvar), method="lm")
})
}
shinyApp(ui = ui, server = server)
output$table <- renderDataTable(trend_data())
在上面的代码中,您的 trend_data
不是反应性数据集。
你可以
制作
trend_data
一个反应性数据集,它会根据您的 Shiny App 中的一些反应性而改变。trend_data <- reactive({ #some code here })
或者直接使用trend_data
output$table <- renderDataTable(trend_data)
并在 plot1 错误中删除 trend_data$
output$plot1 <- renderPlot({
ggplot(trend_data) +
geom_point(aes(Year, `Total Liquid Content`),
size = 3, color = "dark blue") +
geom_smooth(aes(Year, `Total Liquid Content`), size = 1, color = "black", method = "lm") +
labs(title = "Total Precipitation",
x = "Year", y = "Precipitation in Inches") +
theme(text= element_text(size=15, family="Arial"),
plot.title = element_text(hjust = 0.5)) + ylim(15, 55) +
scale_x_continuous(breaks = seq(from = 1940, to = 2000, by = 5))
})