I am using selectInput to get the input from the user and the input which Shiny app will get is the column name in my data.frame. Then in the renderPlot, I tried to plot scatter plot by giving x-axis as selected column and y-axis as other fixed column. My data looks like this
My shiny code:
# Define UI for application that draws a histogram
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 <- read_excel('climate_change_global.xlsx')
gg <- ggplot(climate_change, aes(x=input$ghg, y=temp)) + geom_point() +
geom_smooth(method="lm") + ggtitle("CO2 corelation with temperature is 91%")
gg
})
}
# Run the application
shinyApp(ui = ui, server = server)
But instead it is plotting like this:
I have been trying to fix this since last 4 days, but I am not able to. Please help.