问题
I'm creating a R shinydashboard with a big database that takes a while to load. Is it possible to create a progress bar that displays the information of the amount of data that has been read? (e.g., "Read X% of Z rows")?
回答1:
R cannot tell you how many rows are in your data until the initial load is complete (I think). However, you can use the built in Shiny progress bar to give your users a message that the data is loading:
x<-list.files()
data<-data.frame()
withProgress(message = 'Reading Data!', value = 0, {
for(i in 1:length(x)){
incProgress(1/length(x), detail = paste("File #", i))
hold<-read.csv(x[i])
data<-rbind(data,hold)
}
})
You can just replace the read.csv()
with whatever command you are using (i.e. fread("dt.csv", sep=";",header=T, stringsAsFactors=FALSE)
) to load data. You could also intentionally do more than one big query to inform the progress bar in the loop. If you are loading just one file change the message to something more appropriate (and the loop will only do one cycle, obviously).
来源:https://stackoverflow.com/questions/31397741/r-shinydashboard-display-progress-bar-while-loading-data-fread