首页 > 解决方案 > 在闪亮的上下文中,高度参数不适用于 renderPlotly

问题描述

使用 ggplot,我可以创建我想要的情节。但是,当我转换为 plotly(下面的代码)时,出现错误:

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

我怎样才能解决这个问题?

情节代码

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

标签: rshinyplotly

解决方案


renderPlotly没有height论据。

但是,您可以使用ggplotly'height参数,如下所示:

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)

推荐阅读