我的一个应用程序是通过uiOutput('plot.ui')显示ggplot,而plot.ui是通过renderUI()呈现的。
output$plot.ui=renderUI({
plotOutput('plot', width=a function(), height=a function())
}) 代码可以工作,但它非常滞后。这似乎是一个分两步走的过程。在我的应用程序中,它首先呈现“plot”(这是由renderPlot呈现的ggplot ),然后根据指定的宽度和高度调整plot的大小。两个步骤之间的延迟很大(大约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))
})
}
)非常感谢您的帮助!
发布于 2015-08-03 00:24:04
我也有类似的问题,所以如果你用另一种方式解决了这个问题,请让我知道。我尝试的是根据我正在绘制的内容来调整plotOutput的大小(对于某些输入,我有1条或10条条形的水平条形图。需要相应地调整高度。
解决方案1)按照jcheng5 here的解释调整renderplot()的高度。看看这是否解决了问题
解决方案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())
}这对我很有效。看看这是否解决了问题。
https://stackoverflow.com/questions/30382936
复制相似问题