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

﹥>﹥吖頭↗ 提交于 2019-12-19 07:50:31

问题


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

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