我正在尝试创建带有两个y轴的折线图。 x轴是日期,两个y轴都是连续数据。我有工作代码可以做到这一点。它可以完美地工作,但是当我将其推送到闪亮的服务器(在Ubuntu上)时,出现一个错误,提示“ x”必须是列表。不知道为什么这在本地有效,但在我的闪亮服务器上却无效。
server.R
dataset <- reactive({
infile <- input$datafile
if (is.null(infile)) {
return(NULL)
}
else {read_excel(infile$datapath)}
})
output$plot_data <- renderPlotly({
# Bring in the data
data <- subset(dataset(), select = c(input$date, input$var1, input$var2))
date <- data[[input$date]]
y_var1 <- data[[input$var1]]
y_var2 <- data[[input$var2]]
y1 <- list(tickfont = list(color = "blue"),
side = "left",
title = input$var1
)
y2 <- list(tickfont = list(color = "green"),
overlaying = "y",
side = "right",
title = input$var2
)
plot <- plot_ly() %>%
add_lines(x = date,
y = y_var1,
name = input$var1,
line = list(color = "blue")) %>%
add_lines(x = date,
y = y_var2,
name = input$var2,
yaxis = "y2",
line = list(color = "green")) %>%
layout(title = "Data Over Time",
yaxis = y1,
yaxis2 = y2
)
plot
ui.R
plotlyOutput('plot_data', height = 500)
这是一些具有日期列和两个连续列的示例数据。
Date Impressions Sessions
01/01/2019 34124114 11234323
01/02/2019 43523523 12341244
01/03/2019 56547634 11124324
01/04/2019 65756844 12341234
01/05/2019 32454355 11412432
01/06/2019 23543664 12342412
01/07/2019 23534262 12341244
01/08/2019 12341324 12341234
01/09/2019 34645623 23412341
01/10/2019 64364363 12342123
01/11/2019 24114124 13412342
01/12/2019 23411242 13423442
01/13/2019 24124124 11234242
01/14/2019 42141132 12342144