删除 Plotly 中图表之间的间隙
delete gap between Charts in Plotly
我将图表的大小配置为闪亮但图表之间仍然有空白区域
它们显示为配置高度和宽度之前的旧区域
这是我的代码
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)
})
欢迎使用 Whosebug!
您需要设置 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)
我将图表的大小配置为闪亮但图表之间仍然有空白区域
它们显示为配置高度和宽度之前的旧区域
这是我的代码
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)
})
欢迎使用 Whosebug!
您需要设置 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)