Error in eval: object 'variable' not found (data table feeding plot in Shiny app)

Some careful reading of the renderPlot() source code suggests that you can pass a reactive object to height:

library(shiny)
ui <- fluidPage(
  numericInput("height", "height", 500, step = 10),
  plotOutput("plot")
)
server <- function(input, output, session) {
  height <- reactive({
    input$height
  })
  
  output$plot <- renderPlot({
    plot(1:10)
  }, height = height)
}
shinyApp(ui, server)

Having figured that out, I went back and carefully read the documentation for width and height:

You can also pass in a function that returns the width/height in pixels or 'auto' ; in the body of the function you may reference reactive values and functions.

So for this case, I think the canonical answer would be:

library(shiny)
ui <- fluidPage(
  numericInput("height", "height", 500, step = 10),
  plotOutput("plot")
)
server <- function(input, output, session) {
  output$plot <- renderPlot({
    plot(1:10)
  }, height = function() input$height)
}
shinyApp(ui, server)
1 Like