I am building an RShiny app that includes 1 renderPlot call (in server) with its 1 corresponding plotOutput call (in ui). However, within the renderPlot code, there is a toggle from the ui that switches between two different plots. I would like the plots to have different coordinates. Below is a reproducible RShiny app using generic plots to highlight the aspects of my question:
selector = c("one", "two")
names(selector) = c("one", "two")
plot.width = 600
plot.height = 600
ui <- fluidPage(
fluidRow(
# Organizes the title of the whole shiny app
# ==========================================
column(width = 12, align = 'center',
h2('NBA Shot Chart and Movement Tracking Application'))
),
fluidRow(
# This coordinates the location of the LHS widgets
# ================================================
column(width = 4, align = 'center',
selectInput(inputId = 'shooter.input', label = 'Select Shooter:', multiple = FALSE,
choices = selector, selected = 'one')),
column(width = 8, align = 'left',
plotOutput('shot.chart', width = plot.width, height = plot.height)
)
)
)
server <- shinyServer(function(input, output) {
# renderPlot for the charts (shot charts and movement charts)
output$shot.chart <- renderPlot({
if(input$shooter.input == "one") {
plot(c(1,2,3,4,5), c(6,7,8,9,10))
}
else {
plot(c(1,2,3,4,5), c(1,1,1,1,1))
}
})
})
shinyApp(ui = ui, server = server)
Okay, my question has to do with the plot.width and plot.height parameters set in plotOutput in ui. I want these parameters to change for each of the two plots. When selectInput is set == "one", I want the parameters to be 600 and 600, and when the selectInput is set == "two", I want the parameters to be 600 and 800.
Has anybody run into this problem before, and knows how to deal with it? Thanks!