사용자 입력을 받아서 사용자 입력마다 Postgres 데이터베이스를 쿼리 한 다음 정보를 그려주는 R Shinyweb 페이지가 있습니다. Shiny 응용 프로그램에 상태 표시 줄을 추가하려고합니다.R Shiny SQL 쿼리가 진행 막대를 실행하고 종료하는지 확인합니다.
그러나 내 문제는 쿼리를 실행하는 데 시간이 얼마나 걸리는 지 알 수 없다는 것입니다. 쿼리 실행 시간은 사용자 입력에 따라 다릅니다.
쿼리가 완료 될 때까지 상태 표시 줄을 반복 할 수있는 방법이 있습니까? 그렇다면 어떻게하면 쿼리의 완료를 추적 할 수 있습니까?
다음은 예제 코드입니다. 'plot (rnorm (as.numeric (input $ n_breaks)))')의 줄은 내 코드의 실제 SQL 쿼리입니다. 이 행의 실행 시간은 알 수 없습니다. 나는 실제 코드를 찾고 있지 않다. 이 개념을 구현하는 방법에 대한 아이디어가 필요합니다.
이https://shiny.rstudio.com/articles/progress.html
기본적으로 진행 기능이에게 호출이있는 경우 수행 할 수있는 방법은 없습니다 :
library(shiny)
mycss <- "
#plot-container {
position: relative;
}
#loading-spinner {
position: absolute;
left: 50%;
top: 50%;
z-index: -1;
margin-top: -33px; /* half of the spinner's height */
margin-left: -33px; /* half of the spinner's width */
}
#plot.recalculating {
z-index: -2;
}
"
ui <- fluidPage(
tags$head(tags$style(HTML(mycss))),
actionButton("btn", "Plot (takes 2 seconds)"),
selectInput(inputId = "n_breaks",
label = "Select number of points",
choices = c(100, 1000, 10000, 100000),
selected = 100),
div(id = "plot-container",
tags$img(src = "spinner.gif",
id = "loading-spinner"),
plotOutput("plot")
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
input$btn
i = 0
while (i==0) {
Sys.sleep(1)
plot(rnorm(as.numeric(input$n_breaks)))
i = 1
}
})
}
shinyApp (UI 서버)