在闪亮的应用程序中进行调试时遇到了一些麻烦。我添加了一些新内容后,它不起作用,但是它仍然可以打开闪亮的应用程序平台,尽管某些内容为空白且出现错误消息。桌子和散点图对我不起作用。以下是不断出现的错误。
输出$ table中的错误<-renderDataTable(trend_data()): 找不到“输出”对象”
找不到函数“ 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)
答案 0 :(得分:0)
output$table <- renderDataTable(trend_data())
在上面的代码中,您的trend_data
不是反应性数据集。
您可以
使trend_data
为反应性数据集,该数据集将根据Shiny App中的某些反应性而变化。
trend_data <- reactive({
#some code here
})
或者直接使用趋势数据
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))
})