我目前正在编写一个闪亮的应用程序。我想减少绘图的渲染时间(因为初始化绘图需要很长时间)。假设我要动态绘制图,例如
plot(x=1:10)
(plot
不会是我将在闪亮的应用程序中使用的功能。)
现在,我想将绘图分为以下几个部分:
plot(x=NA, y=NA, xlim=c(0,10), ylim=c(0,10))
points(x=1:10)
在plot(x=NA, y=NA, xlim=c(0,10), ylim=c(0,10))
闪亮的应用中渲染将花费很长时间,并且points(x=1:10)
需要很短的时间。我需要一个plot(x=NA, y=NA, xlim=c(0,10), ylim=c(0,10))
仅在首次加载应用程序时才会执行的过程,然后该图将自底向上构建(将点,线等添加到图中)。有没有人知道如何将其写入应用程序?这里的问题是,我将在闪亮的应用程序中使用的绘图功能不会返回任何内容。绘图功能基于基本graphics
系统(not on ggplot2
,not on lattice
)。
这是此类应用程序的最小工作示例:
library(shiny)
shinyAPP <- function() {
ui <- fluidPage(
sidebarPanel(),
mainPanel(
plotOutput("plotPoints"))
)
server <- function(input, output, session) {
output$plotPoints <- renderPlot(
plot(x=1:10)
## this needs to be replaced with:
##plot(x=NA, y=NA, xlim=c(0,10), ylim=c(0,10))
##points(x=1:10)
)
}
app <- list(ui = ui, server = server)
runApp(app)
}
shinyAPP()
非常感谢你!
所以也许尝试grDevices
,就像这里:
server.R:
library("shiny")
library("grDevices")
data(iris)
plot(x=NA, y=NA, xlim=c(0,10), ylim=c(0,10))
p <- recordPlot()
function(input, output, session) {
output$plotPoints <- renderPlot({
replayPlot(p)
points(1:input$ile)
})
}
和ui.R:
library(shiny)
fluidPage(
sidebarPanel(
sliderInput("ile", min=1, max=10, label="", value=5)
),
mainPanel(
plotOutput("plotPoints"))
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句