버튼을 통해 프런트 엔드의 데이터를 새로 고칠 수있는 반짝이는 앱이 있으며 데이터를 표시합니다. 내 app.R
은 다음과 같습니다 :스크립트를 소싱하는 동안 R 빛나는 동안 로딩 바 표시
library(shiny)
file_name <- "sample.csv"
bkg_color <- "red"
# Define UI for application
ui <- fluidPage(
actionButton("refresh", "", icon("refresh")),
tableOutput("table"),
uiOutput("slider")
)
# Define server logic required
server <- function(input, output, session) {
observeEvent(input$refresh,{
source("updatedata.R")
showModal(modalDialog(
title = "",
"Data refreshed",
easyClose = TRUE,
footer = NULL
))
})
# observe the raw file, and refresh if there is change every 5 seconds
raw <- reactivePoll(5000, session,
checkFunc = function(){
if (file.exists(file_name))
file.info(file_name)$mtime[1]
else
""
},
valueFunc = function(){
read.csv(file_name)
})
output$table <- renderTable(raw())
output$slider <- renderUI({
req(raw())
tagList(
# styling slider bar
tags$style(HTML(paste0(".js-irs-0 .irs-single, .js-irs-0 .irs-bar-edge, .js-irs-0 .irs-bar {background: ",
bkg_color,";border-top: ",bkg_color,";border-bottom: ",bkg_color,"; border: ",bkg_color,"}"))),
sliderInput("date","",
min = min(raw()$v1),
max = max(raw()$v1),
value = max(raw()$v1))
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
가
나는 또한 다음과 같이 데이터 업데이트 않는 다른 updatedata.R
스크립트가 : 사용자가 프런트 엔드에서 새로 고침 단추를 클릭 할 때마다
file_name <- "sample.csv"
temp <- data.frame(v1 =runif(10, min = 0, max = 100), v2 = Sys.time())
write.csv(x =temp, file = file_name,row.names = FALSE)
Sys.sleep(10)
를, 그것은 것입니다 수행 데이터 업데이트. 데이터 새로 고침이 끝나면 데이터가 새로 고쳐지라는 창이 표시됩니다. 내 문제는 데이터를 새로 고치는 동안 '일부 표시'를하고 싶다는 것입니다. shinycssloaders
패키지를 사용해 보았는데 withSpinner(tableOutput("table"))
을 사용했는데 이것이 내 요구 사항을 충족시키지 못합니다. 내가 탐색 할 수있는 옵션이 있습니까?
왜''with withSpinner'' 해결책이 당신을 위해 작동하지 않는가? – amrrs
@amrrs'tableOutput ("table")'부분을'withSpinner'로 감싸는 것처럼 내'output $ table'이 테이블을 렌더링하는 데 시간이 걸리고 다른 스크립트가 있는지를 알지 못하는 경우에만 회 전자를 보여줍니다 이 경우, 내 ** updatedata.R **) – shaojl7