I have a series(100+) of plots that I'd like to display depending on what crime & year the user selects (reactive)
The plots are named already, in this format: "CrimeDataA01" for Assaults in 2001, "CrimeDataM02" for Murder in 2002, etc.
The plots have been defined and the code for them is pasted before shinyServer(function(input, output) in the server file.
I'm trying to get Shiny to print the correct plot, depending on what crime and year the user selects. Here is my server.r code:
shinyServer(function(input, output) {
crime2 <- switch(input$select,
"Assault" = "A",
"Burglary" = "B",
"Car Theft" = "MT",
"Grand Larceny" = "G",
"Murder" = "M",
"Rape" = "R",
"Robbery" = "RO")
year2 <- switch(input$Slider,
"2000" = "00",
"2001" = "01",
"2002" = "02",
"2003" = "03",
"2004" = "04",
"2005" = "05",
"2006" = "06",
"2007" = "07",
"2008" = "08",
"2009" = "09",
"2010" = "10",
"2011" = "11",
"2012" = "12",
"2013" = "13",
"2014" = "14",
"2015" = "15")
output$plot <- plot(paste0("CrimeData", crime2, year2))
})
})
Here is my ui.R code:
library(shiny)
shinyUI(fluidPage(
sidebarLayout( position = "right",
sidebarPanel(
selectInput("select", label = h3("Select Crime"),
choices = list("Assault" = 1, "Burglary" = 2, "Car Theft" = 3, "Grand Larceny" = 4, "Murder" = 5, "Rape" = 6, "Robbery" = 7))
),
mainPanel(
textOutput("text1"),
h1("NYC Crime Over Time", align = "center"),
sliderInput("Slider", "Year", 2000, 2015, 2000),
print(plot)
))))
I've messed with it so much I don't know what is up or down anymore. I'd just like it to call the correct plot and display it
output$plottooutput$MyPlotand userenderImage()instead ofplot(). then changeprint(plot)to plotOutput("MyPlot"). See the example in?renderImage- Brandon Bertelsen