首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >滞后闪亮的uiOutput

滞后闪亮的uiOutput
EN

Stack Overflow用户
提问于 2015-05-22 03:41:23
回答 1查看 718关注 0票数 1

我的一个应用程序是通过uiOutput('plot.ui')显示ggplot,而plot.ui是通过renderUI()呈现的。

代码语言:javascript
复制
  output$plot.ui=renderUI({
   plotOutput('plot', width=a function(), height=a function())
   }) 

代码可以工作,但它非常滞后。这似乎是一个分两步走的过程。在我的应用程序中,它首先呈现“plot”(这是由renderPlot呈现的ggplot ),然后根据指定的宽度和高度调整plot的大小。两个步骤之间的延迟很大(大约3秒)。我通过在plotOutput()周围包装一个withProgress()来检查它,问题仍然存在。我想知道为什么这个问题会存在,是否有任何方法可以解决它。

下面给出一个小例子来说明这个问题。

代码语言:javascript
复制
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))
    })
  }
)

非常感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2015-08-03 00:24:04

我也有类似的问题,所以如果你用另一种方式解决了这个问题,请让我知道。我尝试的是根据我正在绘制的内容来调整plotOutput的大小(对于某些输入,我有1条或10条条形的水平条形图。需要相应地调整高度。

解决方案1)按照jcheng5 here的解释调整renderplot()的高度。看看这是否解决了问题

解决方案2)定义一个绘图函数,使用isolate()

代码语言:javascript
复制
# 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())
}

这对我很有效。看看这是否解决了问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30382936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档