Вам необходимо заменить x=input$ghg
в коде ggplot
на x=get(input$ghg)
:
library(shiny)
library(ggplot2)
dat <- structure(list(year = 1970:1981, flood = c(31L, 15L, 15L, 20L,
19L, 17L, 17L, 48L, 47L, 34L, 39L, 43L), CO2_emissions = c(14788798L,
15323176L, 15957193L, 16822109L, 16850822L, 16745792L, 17726098L,
18279804L, 18497906L, 19533548L, 19324327L, 18726247L), methane_emissions = c(5305820L,
5145430L, 5360610L, 5421500L, 5379140L, 5503270L, 5649430L, 5796380L,
5795950L, 5972760L, 6011410L, 5871770L), nitrous.oxide = c(2225930L,
2089239L, 2245411L, 2291021L, 2240345L, 2329579L, 2412556L, 2524966L,
2552326L, 2710504L, 2732926L, 2636113L), HFC_PFC_SF6 = c(4516068L,
3266672L, 3999660L, 3880678L, 3357342L, 3642854L, 3876927L, 4303459L,
4341088L, 4947684L, 5039591L, 4554856L), temp = c(0.0372, -0.0783,
0.0264, 0.1641, -0.0719, 0.0034, -0.0792, 0.1978, 0.1123, 0.2273,
0.2637, 0.2999), glacier_melt = c(-10.128, -10.288, -10.441,
-10.538, -10.613, -10.534, -10.633, -10.682, -10.754, -11.127,
-11.318, -11.394)), class = "data.frame", row.names = c(NA, -12L
))
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
selectInput(inputId = "ghg", label = "Choose a Coral type",
c("CO2" = "CO2_emissions",
"Methane" = "methane_emissions",
"Nitrous Oxide" = "nitrous_oxide",
"Other" = "HFC_PFC_SF6")),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
climate_change <- dat #read_excel('climate_change_global.xlsx')
gg <- ggplot(climate_change, aes(x=get(input$ghg), y=temp)) + geom_point() +
geom_smooth(method="lm") + ggtitle("CO2 corelation with temperature is 91%")+
xlab(input$ghg)
gg
})
}
# Run the application
shinyApp(ui = ui, server = server)