[英]laggy Shiny uiOutput
我的應用程序之一是通過uiOutput('plot.ui')
顯示ggplot,而plot.ui是通過renderUI()
呈現的。
output$plot.ui=renderUI({
plotOutput('plot', width=a function(), height=a function())
})
該代碼可以工作,但是非常麻煩。 看來這是一個兩步過程。 在我的應用程序中,它首先渲染“圖”(由renderPlot渲染的ggplot),然后根據指定的寬度和高度調整圖的大小。 這兩個步驟之間的時滯很大(大約3秒)。 我通過在plotOutput()周圍包裹withProgress()進行了檢查,問題仍然存在。 我想知道為什么這個問題存在,是否有任何辦法可以解決。
附帶一個小示例來說明此問題。
library(shiny)
shinyApp(
ui=shinyUI(
pageWithSidebar(
titlePanel('test'),
sidebarPanel(
sliderInput('width','Width: ', min=0,max=1000,value=100),
sliderInput('height','Height: ', min=0,max=1000,value=100)
),
mainPanel(uiOutput('plot.ui'))
)
),
server=function(input,output){
output$plot.ui=renderUI({
plotOutput('plot',width=input$width,height=input$height)
})
output$plot=renderPlot({
plot(runif(100000,1,100),runif(100000,1,100))
})
}
)
非常感謝您的幫助!
我遇到了類似的問題,因此,如果您以其他方式解決了該問題,請告訴我。 我試圖根據我的繪圖內容來調整plotOutput的大小(對於某些輸入,我有水平條形圖,其中有1條或10條..需要相應地調整高度。
解決方案1)調整renderplot()的高度,如jcheng5此處所述 。 看看這是否解決了問題
解決方案2)定義一個繪圖函數,使用isolate()
# Define a function that returns a plot
plot_function <- function(){
plot(runif(100000,1,100),runif(100000,1,100)
}
# reactive UI and adjust the height here
output$plot.ui=renderUI({
plotOutput("plot", height = -------------)
})
# call plot_function but use isolate()
output$plot <- renderPlot({
isolate(plot_function())
}
這對我有用。 查看是否可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.