Nader Mehri
Nader Mehri

Reputation: 556

Height argument is not working with renderPlotly within shiny context

Using ggplot, I could create my desired plot. However, when I converted to plotly (the code below), I got an error:

Error in renderPlotly({ : unused argument (height = function() {
    400 + (length(workforce_data()[["County.y"]]) * 5)
}).

How can I fix this?

plotly code

output$workforce_plot <- renderPlotly ({
   workforce_plot()
 }  , height = function() {400 + (length(workforce_data()[["County.y"]]) *5) })

Upvotes: 0

Views: 548

Answers (1)

ismirsehregal
ismirsehregal

Reputation: 33397

renderPlotly doesn't have a height argument.

However, you can use ggplotly's height argument as follows:

library(plotly)
library(shiny)

ui <- fluidPage(
  sliderInput("heightSlider", "Plot heigth [px]", min = 200L, max = 1000L, value = 500L),
  plotlyOutput("myPlot")
)

server <- function(input, output, session) {
  output$myPlot <- renderPlotly({
    p <- ggplot(data.frame(x = 1:10, y = runif(10)), aes(x, y)) + geom_point()
    ggplotly(p, height = input$heightSlider)
  })
}

shinyApp(ui, server)

Upvotes: 1

Related Questions