避免Shiny中重叠的情节子图

时间:2017-07-31 21:44:20

标签: shiny plotly overlap

我一直在努力寻找避免重叠子图的最佳方法。我尝试了自动调整大小,其中高度取决于行数,但绘图图形与其下方的前进小部件(在本例中为数据表)重叠。子图的数量根据用户输入而变化。

这是我得到的图像:enter image description here

plotly:: subplot(subplots, nrows = rows,titleY = TRUE) %>%
   layout(margin = list(b=200)) #,autosize=F, height=(300*rows))

有谁知道如何渲染避免这些重叠问题的情节子图?

1 个答案:

答案 0 :(得分:0)

我发现的最佳答案是在构建情节图时创建反应。动态变化的高度应基于用户输入。在我的例子中,是用户选择在图中显示的进程和影响类别的数量,所以我提出了像height = 100 * n_pro * n_imp这样的关系。此高度应传递到plot_ly()(以及renderUI)。然后,renderPlotly调用reactive,后者又由renderUI调用。在我的情况下,我保持宽度为100%,但也可以更新。它看起来如下:

fig_creation = reactive({
      height = (something based on user input$)
      plot_ly(..., height = height)
)}

output$plotlyFig = renderPlotly({ fig_creation() })

output$figPlotly = renderUI({
        height = (something based on user input$) + 100 #the 100 is a buffer
        plotlyOutput("plotlyFig",width = "100%", height = paste0(height)
 })

在UI方面,您只需使用uiOutput(“figPlotly”),即可放置图形。

相关问题