I am trying to create a shiny app that:
- Let's the user upload a CSV file
- Select independent (year or month column) and dependent variables (tmean/TMin/TMax columns)
- Based on the selected variables, the app will return a regression summary.
- Based on the selected variables, the app will also return a geom_line plot with the regression/slope line.
However I get this error:
Warning: Error in group by: Must group by variables found in `.data`.
x Column `2010_2021` is not found.
How can I fix this?
Data:
The file can be downloaded from
CodePudding user response:
Several points:
- you need
.data
only in the cases where you want to access data via a variable that contains a string, if the name of the symbol (variable) is the variable name in the data.frame, you don't need.data
- typo, you've forgot the
ggplot
- to avoid errors due to uninitialised
input
s, use areq
in your plot rendering
output$RegPlots = renderPlotly({
req(mydf(), input$independent, input$dependent)
mydf() %>% group_by(year) %>%
summarise(avgTemp = mean(.data[[input$independent]])) %>%
ungroup %>%
ggplot(aes(x = .data[[input$dependent]], y = avgTmean))
geom_point(color = "deepskyblue4")
geom_smooth(method = lm, linetype = 2, color = "red4", se = F)
theme(text = element_text(size = 16))
xlab("Year")
ylab("Temperature (C)")
ggtitle("1980-2021 Regression Plot")
})