R Shiny error: object input not found
I've solved this issue with "<<-". I don't know for sure, but it is related to global environment:
output$SpendChart <- renderPlot({
choice <<- input$split
Country <- spend$Principal.Place.of.Performance.Country.Name
ggplot(spend, aes(x = Country, y = choice)) + geom_bar(stat = "identity")
})
The problem is with ggplot evaluating the variable in the context of the data frame provided, spend in your case. What you want is:
ggplot(spend, aes_string(x = "Country", y = input$split))
So your working server.R code is:
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
spend <- data.frame(Country = c("Turk", "Turk", "Saudi", "Saudi", "Ger", "Ger"),
Action.Obligation = c(120,-345,565,-454, 343,-565),
Action_Absolute_Value = c(120,345,565,454,343,565))
output$SpendChart <- renderPlot({
ggplot(spend, aes_string(x = "Country", y = input$split)) +
geom_bar(stat = "identity")
})
})
Obviously, you can replace the spend df with your CSV import.