闪亮R模型训练进度条

问题描述:

我正在制作一个Shiny应用程序,在点击actionButton时,使用插入程序包训练模型。由于这次培训需要时间 - 大约4-5分钟 - 我想显示一个进度条,随着模型的训练而进展。闪亮R模型训练进度条

感谢

+0

请接受的答案,如果这是对您有所帮助。 – Santosh

要闪亮的应用程序显示进度条,你需要使用withProgress功能server如下:

withProgress(message = "Model is Training", value = 1.0, {    
    ## Your code 
}) 

所以,你把你的代码,这个函数里面,它会显示消息代码运行时,“模型就是训练”。该函数中的value是应用中的进度指示器(1.0是100%)。这可以根据计算进行设置。例如,您可以设置value = min + (max - min) * 0.1。它不需要完全像这样。任何依赖于代码的适合你的东西。设置value = 1.0不会受到伤害,因为它在您的案例“模型是培训”中显示了具有意义且相关消息的进度条。

要获得更多信息,请访问此链接:https://shiny.rstudio.com/reference/shiny/latest/withProgress.html

+0

亲爱的@Santosh,这似乎不工作,我试图运行此代码: - observeEvent(输入$ trainModelButton,{ print(“Training Begins”) withProgress(“Model is being Trained”,value = 1.0,{ train(demand〜temp,dataProcessed_Internal,'rf',ntree = 50) }) –

+0

为什么在代码中写入print(“Training Begins”)?闪亮的应用程序不会使用“打印”功能进行打印。你需要使用'renderText'。有没有错误,你得到了吗?因为显示进度条很简单。我已经实现了它一千次。你只需要将代码放在'withProgress'函数中,就像我在我的答案中所建议的那样。 – Santosh

+0

'observeEvent(输入$ trainModelButton,{ withProgress( “模型被训练”,值= 1.0,{ 列车(需求〜温度,dataProcessed_Internal, 'RF',ntree = 50) }) })'这应该工作。如果出现问题,必须使用“observeEvent”和您的火车模型。 – Santosh