【问题标题】:delete gap between Charts in Plotly删除 Plotly 中图表之间的差距
【发布时间】:2020-05-01 20:43:51
【问题描述】:

我将图表的大小设置为闪亮,但图表之间仍有空白区域

它们在配置高度和宽度之前显示为旧区域

这是我的代码

plot1_reactive <- eventReactive(input$submit_but,{
      xaxis <- list(
                    tickformat = "%-d/%-m/%Y",
                    type='category'
                    )
      yaxis <- list(title = input$sel_par1)
      r <- plot_ly(mydata,x=date,y = a , type = 'scatter', mode = 'lines+markers'
                   , width = 950, height = 200,line = list(shape = "linear"))%>%
      layout(xaxis = xaxis, yaxis = yaxis) 

    })
    plot2_reactive <- eventReactive(input$submit_but,{
      xaxis <- list(
                    tickformat = "%-d/%-m/%Y",
                    type='category')
      yaxis <- list(title = input$sel_par2)
      r <- plot_ly(mydata,x=date,y = b , type = 'scatter', mode = 'lines+markers'
                   , width = 950, height = 200,line = list(shape = "linear"))%>%
        layout(autosize = F,xaxis = xaxis, yaxis = yaxis)  
    })

【问题讨论】:

    标签: plot shiny plotly r-plotly


    【解决方案1】:

    欢迎使用 stackoverflow!

    您需要设置plotlyOutput (UI) 的height 参数,而不是plot_ly 调用(服务器)中的参数。否则将应用默认的 400px。

    请参阅以下可重现示例:

    library(shiny)
    library(plotly)
    
    ui <- fluidPage(
      plotlyOutput("p1Out", height = "200px"),
      plotlyOutput("p2Out", height = "200px"),
      plotlyOutput("p3Out", height = "200px")
    )
    
    server <- function(input, output, session) {
      output$p3Out <- output$p2Out <- output$p1Out <- renderPlotly({
        plot_ly(y=1:10, type = "scatter", mode = "lines+markers")
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 1970-01-01
      • 2015-10-10
      • 2023-01-02
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多