1

I am trying to resize a plotOutput ui object in shiny

library(shiny)

ui <- fluidPage(
  fluidRow(
        column(6, numericInput('save.height', "Save height (mm)", value = 50)),
        column(6, numericInput('save.width', "Save width (mm)", value = 43))),
  plotOutput('plot_display', width = '50mm', height = '43mm'))

server <- function(input, output) {
  output$plot_display <- renderPlot({

    ggplot(iris, aes(x = Species, y = Petal.Length)) +
      stat_summary(geom = 'bar', fun.y = mean) +
      geom_point() +
      theme(aspect.ratio = 1)

  })


}

shinyApp(ui, server)

I haven't been able to find something equivalent to updateNumericInput() to update the values dynamically in plotOutput

2 Answers 2

5

You could also use the awesome shinyjqui package:

library(shiny)
library(shinyjqui)

shinyApp(
  ui = fluidPage(
          jqui_resizabled(plotOutput('hist'))
  ), 
  server = function(input, output) {
    output$hist <- renderPlot({
      hist(rnorm(100))
    })
  }
)

See here: https://github.com/Yang-Tang/shinyjqui. enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

That's a really cool package, thanks! Is there any way to access the values associated with the plot size when resizing?
4

In order to do that you must indicate that the size of your output depends on the value of the input. You can find a working example below :

library(shiny)
library(ggplot2)

ui <- fluidPage(
 fluidRow(
  column(6, numericInput('save.height', "Save height (mm)", value = 500)),
  column(6, numericInput('save.width', "Save width (mm)", value = 450))),
  plotOutput('plot_display'))

server <- function(input, output) {
 output$plot_display <- renderPlot({

ggplot(iris, aes(x = Species, y = Petal.Length)) +
  stat_summary(geom = 'bar', fun.y = mean) +
  geom_point()

},height = function()input$save.height, width = function()input$save.width)}

shinyApp(ui, server)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.