问题
I am making a Shiny App in which, at the click of the actionButton, a model is trained using the caret package. As this training takes time - approximately 4-5 minutes - I wanted to display a progress bar which progresses as the model is trained.
Thanks
回答1:
To display progress bar in shiny app, you need to use withProgress
function in server
as below:
withProgress(message = "Model is Training", value = 1.0, {
## Your code
})
So, you put your code inside this function and it will display the message "Model is training" while your code is running. value
in the function is a progress indicator in the app (1.0 is 100%). This you can set depending on computation. For example, you can set value = min + (max - min) * 0.1
. It needs not to be exactly like this. Anything that works for you which depend on the code. Setting value = 1.0
wouldn't hurt because it display the progress bar with its meaningful and relevant message in your case "Model is Training".
To get more info, visit this link: https://shiny.rstudio.com/reference/shiny/latest/withProgress.html
来源:https://stackoverflow.com/questions/46700360/progress-bar-for-model-training-in-shiny-r