【发布时间】:2021-10-18 22:04:54
【问题描述】:
我制作了一个闪亮的应用程序,其中包括一个 interactive plot 通过ggplotly 在R 中。为了将其中两个交互式绘图一起绘制,我使用了plotly::subplot。子图按预期工作正常,但是两者的标题在 Shiny 应用程序中消失了。
如何解决这个问题?
相关代码:
# Define UI for application that draws a plotlys
options(shiny.maxRequestSize=30*1024^2)
ui = navbarPage("Title", theme = shinytheme("spacelab"),
tabPanel("Interactive Plot",
icon = icon("chart-area"),
# Show plots side by side
splitLayout(
plotlyOutput(outputId = "Comparison_Plots"),
width = "1080px",
height = "1280px")))
# Tell the server how to assemble inputs into outputs
server = function(input, output) {
output$Comparison_Plots = renderPlotly({
....
fig1 = ggplotly(gg_plot1, tooltip = "text")
fig2 = ggplotly(gg_plot2, tooltip = "text")
# Plot them together
sub_plot = subplot(fig1, fig2, margin = 0.05) %>%
layout(annotations = list(
list(x = 0 , y = 1.1, text = "Group 1", showarrow = FALSE, xref='paper', yref='paper'),
list(x = 1 , y = 1.1, text = "Group 2", showarrow = FALSE, xref='paper', yref='paper'))
)
sub_plot
})
}
查看器窗口的快照仅显示sub_plot
sub_plot 的快照如通过Shiny app 显示的那样
【问题讨论】:
-
如果我从
plotlyOutput中删除height和width参数,标题会重新出现,但是我无法调整绘图的大小。
标签: r shiny plotly r-plotly ggplotly