我的代码在这篇文章的最后,但我会先说明问题。我有一个页面应该在页面加载时显示图表(从合成数据生成)。其中两个图需要一些时间,因此当页面加载时,格式化通常看起来非常时髦,如下所示。有时它会自行修复,有时它在用户按下按钮重新生成绘图之前根本不会自行修复。您可以在此处查看滞后版本:
在这里你可以看到它完成/恢复时的版本:
有没有办法避免这种行为?
我正在粘贴下面的代码:
ui.R
shinyUI(fluidPage(theme="style.css",
headerPanel("Atomic point contact break-junction traces"),
#row 1
fluidRow(
column(1),
column(3, wellPanel(
br(),
p("Click the button to see a new trace.", align="center"),
br(),
actionButton('samp','New Sample', align="center")
)),
column(1),
column(3, wellPanel(
plotOutput("trace", height="300px", width = "300px")
)),
column(3, wellPanel(
plotOutput("G0steps", height="300px", width = "300px")
))
),
#row 2
fluidRow(
column(1),
column(3, wellPanel(
br(),
p("Click the button to see an aligned 2d histogram"),
actionButton('button2D', 'See Steps')
)),
column(2),
column(4, wellPanel(
plotOutput("hist2D")
))
),
#row 3
fluidRow(
column(1),
column(3, wellPanel(
br(),
p("Click the button to see steps identified"),
actionButton('buttonSteps', 'See Steps'),
br(),
p("Click the button to see clusters of steps identified"),
actionButton('clusterButton', 'See Clusters')
)),
column(1),
column(3, wellPanel(
plotOutput("stepsShow")
)),
column(1),
column(3, wellPanel(
plotOutput("clustersShow")
))
)
))
这是server.R:
shinyServer(function(input, output) {
# initial loading of plots:
trace = makeTrace()
output$trace <- renderPlot({
plot(trace)
})
output$G0steps <- renderPlot({
plot(alignG(.1, trace ))
})
output$stepsShow <- renderPlot({
findJumps(beginG =1.5, endG = .1, trace = makeTrace(), loq=1)
})
output$hist2D <- renderPlot({
make2DHist()
})
output$clustersShow <- renderPlot({
clust.size <- 3
numTraces <-30
list_df <- makeClusters(numTraces)
df1 <- list_df[[1]]
drops <- c("Trace")
df1.clust <- df1[,!(names(df1) %in% drops)]
df1C <- bestCluster(df1.clust, clust.size, df1)
df1C$clusterCat <- factor(df1C$Cluster)
plot.cats <- ggplot(df1C, aes(x=Noise, y = AvgC), colour=clusterCat) + geom_point( aes(color=clusterCat, size=4))
plot.cats
})
#row 1
observe({
if(input$samp > 0) {
trace = makeTrace()
output$trace <- renderPlot({
plot(trace)
})
output$G0steps <- renderPlot({
plot(alignG(.1, trace ))
})
}
})
#row 2
observe({
if(input$button2D > 0) {
make2DHist()
output$hist2D <- renderPlot({
make2DHist()
})
}
})
#row 3
observe({
if(input$buttonSteps > 0) {
findJumps(beginG =1.5, endG = .1, trace = makeTrace(), loq=1)
output$stepsShow <- renderPlot({
findJumps(beginG =1.5, endG = .1, trace = makeTrace(), loq=1)
})
}
})
observe({
if(input$clusterButton > 0) {
clust.size <- 3
numTraces <-30
list_df <- makeClusters(numTraces)
df1 <- list_df[[1]]
drops <- c("Trace")
df1.clust <- df1[,!(names(df1) %in% drops)]
df1C <- bestCluster(df1.clust, clust.size, df1)
df1C$clusterCat <- factor(df1C$Cluster)
plot.cats <- ggplot(df1C, aes(x=Noise, y = AvgC), colour=clusterCat) + geom_point( aes(color=clusterCat, size=4))
plot.cats
output$clustersShow <- renderPlot({
plot.cats
})
}
})
})
答案 0 :(得分:0)
通过在plotOutput中设置高度和宽度,可以避免这种奇怪的大小调整延迟。如果你想从一开始就正确加载它,显然将它保留在auto状态就不起作用了。