【发布时间】:2020-04-11 23:11:17
【问题描述】:
我在闪亮的应用程序中调试时遇到了一些问题。我添加了一些新东西后它不起作用,但它仍然能够打开闪亮的应用程序平台,尽管某些内容是空白并显示错误消息。表格和散点图对我不起作用。以下是不断出现的错误。
输出$table
找不到函数“y”
我不知道如何使表格和绘图图工作。
# 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)
【问题讨论】: