从 Plotly 4.5.6 升级到 Plotly 4.6.0(或更高版本)后,在plot_ly. 这发生在窗口大小调整或 tabsetPanel 选择时。
先决条件
plot_ly(..., height=<some dependency>)<some dependency>是一个反应值(input$height在下面的例子中)问题
例子
selectInput(100px)的第一个值,即使此值根本没有更改:如果tabsetPanel页面中有 ,也会发生同样的问题(例如在绘图下方)。单击不同的选项卡时,绘图高度会更改。
library(shiny)
library(plotly)
ui <-shinyUI(fluidPage(
selectInput("height", "Choose desired height", choices=c(100,800)),
plotlyOutput("plot")))
server <- shinyServer(function(input,output, session){
output$plot <- renderPlotly({
plot_ly(mtcars, x=~gear, y=~cyl, height = input$height)
})
})
shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的
height参数放入renderPlotly工作中,但由于 Plotly 本身从不改变其高度,因此绘图本身始终保持在 800px(只是容器高度发生了变化):用户界面: uiOutput("plot")
服务器:
output$plot <- renderUI({ plotlyOutput("plotly", height=input$height) })
output$plotly <- renderPlotly({ plot_ly(mtcars, x=~gear, y=~cyl)})
Run Code Online (Sandbox Code Playgroud)
output$plotly依赖于 时input$height,绘图在选择任何其他高度后立即“跳跃”:output$plotly <- renderPlotly({ plot_ly(mtcars, x=~gear, y=~cyl, height=input$height) })
请注意,如果tabsetPanel绘图下方有一个简单的并且在那里选择了另一个选项卡,所有这些也会发生。
这个问题终于被修复了,请参阅github 上的这个错误:。在plotly 包版本4.8.0中,此行为已得到纠正。
请注意,您需要将 100% 的高度添加到plotlyOutput,即plotlyOutput("plot", height = '100%')完整的解决方案(这会适当地设置不可见的容器空间)。
| 归档时间: |
|
| 查看次数: |
635 次 |
| 最近记录: |