R 滞后输出
我的一个应用程序通过uiOutput'plot.ui'显示ggplot,plot.ui通过renderUI呈现 代码可以工作,但非常滞后。这似乎是一个分两步的过程。在我的应用程序中,它首先渲染“plot”,这是由renderPlot渲染的ggplot,然后根据指定的宽度和高度调整绘图的大小。两个步骤之间的延迟约为3秒。我通过在plotOutput周围包装一个withProgress来检查它,问题仍然存在。我想知道为什么会存在这个问题,以及是否有办法解决它 附上一个小例子来说明这个问题R 滞后输出,r,shiny,R,Shiny,我的一个应用程序通过uiOutput'plot.ui'显示ggplot,plot.ui通过renderUI呈现 代码可以工作,但非常滞后。这似乎是一个分两步的过程。在我的应用程序中,它首先渲染“plot”,这是由renderPlot渲染的ggplot,然后根据指定的宽度和高度调整绘图的大小。两个步骤之间的延迟约为3秒。我通过在plotOutput周围包装一个withProgress来检查它,问题仍然存在。我想知道为什么会存在这个问题,以及是否有办法解决它 附上一个小例子来说明这个问题 libra
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调整渲染地块的高度 正如他所解释的那样。看看这是否解决了问题 解决方案2定义绘图函数,使用隔离
# 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())
}
这对我有用。看看这是否解决了问题。它没有光泽。。。在我的机器上运行plotrunif100000,1100,runif100000,1100需要一两秒钟。这有很多点需要考虑。
# 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())
}