I am trying to change the data frame that ggplot uses to render a graph given a selection of a drop down menu.
The dropdown menu works but the graph will not render.
for reference 'school' is a set of strings with the names of teams.
library(shiny)
library(shinydashboard)
library(ggplot2)
ui <- dashboardPage(
dashboardHeader(title = "NCAA - Lorenz"),
dashboardSidebar(
sidebarMenu(
menuItem("teams", tabName = "teams"),
menuItem("Correlation", tabName = "Correlation"))),
dashboardBody(
tabItems(
tabItem("teams",
box(plotOutput("GINI_plot"), width = 4),
box(
selectInput("TEAM","TEAM:",
c(teams)), width = 4)),
tabItem("Correlation",
box(plotOutput("correlation_plot"), width = 4),
box(
selectInput("STATISTIC","STATISTIC:",
c("DRtg","Pts","ast")), width = 4))
)
)
)
server <- function(input, output){
df <- reactive({
get(input)
})
output$GINI_plot <- renderPlot({
ggplot(data = df, aes(CUMSUM,CUMperpts)) +
geom_abline(intercept = 0, slope = 1)
})
output$correlation_plot <- renderPlot({
plot(schdata[[input$STATISTIC]], schdata$gini, ylab = "Gini Coef.", xlab = "STATISTIC")
})
}
shinyApp(ui, server)
the box in the dash board reads "Error: [object Object]" This is the error output in rstudio
Warning: Error in ggplot: `data` cannot be a function.
ℹ Have you misspelled the `data` argument in `ggplot()`
175: <Anonymous>
174: signalCondition
173: signal_abort
172: rlang::abort
171: cli::cli_abort
170: ggplot.function
168: renderPlot [/home/thrash-libre/R-projects/application.R#35]
166: func
126: drawPlot
112: <reactive:plotObj>
96: drawReactive
83: renderFunc
82: output$GINI_plot
1: runApp
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Anything helps .
The ggplot command should just read the dataframe variable and output a graph.
I have also tried to select from a list of dataframe but that didnt work either