某些包(如timetk
、plot_ly
(的plot
函数不会生成写入renderPlot
函数中的plot(output)
。尽管当我在控制台中运行output(plot)
时,同一段代码会返回它。与plot()
一样,ggplot()
也起作用。为什么会这样?
这段带有timetk库的代码在rstudio控制台中提供输出:
dataset %>%
plot_time_series(.date_var = Year, .value = column1,
.interactive = TRUE, .y_lab = "Amt", .x_lab = "Year",
)
但如果在renderPlot
函数中写入相同的部分,它不会在RShiny应用程序上提供输出,只是显示一个空白的白色屏幕。
UI:UI代码都很好。我也写了一本plotOutput("p1")
。
服务器:
output$p1 <- renderPlot({
dataset %>%
plot_time_series(.date_var = Year, .value = column1,
.interactive = TRUE, .y_lab = "Amt", .x_lab = "Year",
)
})
问题是renderPlot
和plotOutput
用于基本图或ggplot。当你想制作一个交互式的plotly
图表时,你必须使用plotly::renderPlotly
和plotly::plotlyOutput
。