Мой код в конце этого сообщения, но сначала я сформулирую проблему. У меня есть страница, на которой должны отображаться графики (созданные из синтетических данных) при загрузке страницы. Два из графиков занимают некоторое время, и по этой причине, когда страница загружается, форматирование обычно выглядит довольно напуганным, как вы можете видеть ниже. Иногда он исправляет себя, и иногда он вообще не фиксируется, прежде чем пользователь нажмет кнопку, чтобы восстановить сюжет. Вы можете увидеть лаг версии здесь:R shiny - weird resizing lag при загрузке участков из медленных вычислений при первом открытии app
И здесь вы можете увидеть версию, когда он закончил/восстановленный:
Есть ли способ избежать этого?
Я вставив свой код ниже:
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
})
}
})
})