Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help for renderCachedPlot gives bad advice for specifying height/width #2984

Open
brooksambrose opened this issue Jul 28, 2020 · 1 comment

Comments

@brooksambrose
Copy link

brooksambrose commented Jul 28, 2020

shiny::renderCachedPlot throws "formal argument matched by multiple actual arguments" error when specifying height or width. The help page says that dots are passed to grDevices::png:

... Arguments to be passed through to png. These can be used to set the width, height, background color, etc.

In fact the dots are passed to shiny:::DrawPlot where height and width are specified from the sizePolicy argument. Thus following the docs as written leads to an error. While I expect the code represents the intended behavior, I would suggest improving the docs to explain that height or width cannot be specified in the same way as renderPlot, and possibly building in a warning that issues guidance about fixing the problem. To reproduce the behavior of renderPlot one must set sizePolicy with a growth rate of 1, e.g. sizeGrowthRatio(width = 400, height = 400, growthRate = 1).

library(shiny)

ui <- fluidPage(
  titlePanel("Hello Shiny!"),
    mainPanel(
      plotOutput(outputId = "renderPlot")
      ,plotOutput(outputId = "renderCachedPlot")
      ,plotOutput(outputId = "renderPlot_hw")
      ,plotOutput(outputId = "renderCachedPlot_hw")
      ,plotOutput(outputId = 'renderCachedPlot_sizePolicy')
    )
  )

server <- function(input, output) {
  output$renderPlot <- renderPlot({
    hist(faithful$waiting, main = "renderPlot, height/width default")
    })
  output$renderCachedPlot <- renderCachedPlot({
    hist(faithful$waiting, main = "renderCachedPlot, height/width default")
    },cacheKeyExpr = '')
  output$renderPlot_hw <- renderPlot({
    hist(faithful$waiting, main = "renderPlot, height/width 400")
    },height=400,width=400)
  output$renderCachedPlot_hw <- renderCachedPlot({
    hist(faithful$waiting, main = "renderCachedPlot, height/width 400")
    },cacheKeyExpr = '',height=400,width=400)
  output$renderCachedPlot_sizePolicy <- renderCachedPlot({
    hist(faithful$waiting, main = "renderCachedPlot, height/width 400")
    },cacheKeyExpr = '',sizePolicy = sizeGrowthRatio(width = 400, height = 400, growthRate = 1))
}
shinyApp(ui = ui, server = server)
#> 
#> Listening on http://127.0.0.1:7185
#> Warning: Error in drawPlot: formal argument "width" matched by multiple actual
#> arguments
#> Warning in log(x/base, rate): NaNs produced

#> Warning in log(x/base, rate): NaNs produced

Created on 2020-07-27 by the reprex package (v0.3.0)

@akshat-max
Copy link

Hey I am new to open source and really want to get kick start to it can you assign me this issue if it's open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants