【发布时间】:2019-03-29 02:57:43
【问题描述】:
我试图找到一种方法来避免在加载绘图之前在 Shiny 中切换选项卡时无需重新加载完整绘图的情况下调整大小问题。下面给出了重现该问题的最小示例,方法是从正态分布幅度时间中抽取样本,然后绘制直方图作为计算密集型图的占位符。
time_waste<- function(magnitude) {
y<-0
for(i in 1:magnitude) {
y<- y + rnorm(1,0,1)
}
return(abs(y))
}
ui <- fluidPage(sidebarLayout(
sidebarPanel(width = 3,
fluidRow(
column(
4,
numericInput(
inputId = "magnitude",
label = "magnitude",
value = 1000000
)))),
mainPanel(width = 8,
tabsetPanel(id = "tabset",
tabPanel("Plot1", plotlyOutput("p1", height = "700px")),
tabPanel("Plot2", plotlyOutput("p2", height = "700px"))))
)
)
server<- function(input, output, session) {
y<- reactive({
rep(time_waste(time_waste(input$magnitude)),3)
})
output$p1 <- renderPlotly({
p<- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = y(),
name = "SF Zoo",
type = "bar"
)
})
output$p2<- renderPlotly({
p<- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = y(),
name = "SF Zoo",
type = "bar"
)
return(p)
})
}
app <- shinyApp(ui, server)
runApp(app)
卡住的情节看起来像链接的图像: Stuck Plot
如果以任何方式调整了绘图的大小(例如,通过调整其所在窗口的大小)并且固定的绘图宽度不会出现问题,则绘图会正确显示。
提前致以诚挚的问候和感谢。
【问题讨论】: