R shinydashboard: display progress bar while loading data (fread)

删除回忆录丶 提交于 2019-12-01 06:10:14

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!