计算过程中的反应函数

时间:2017-04-18 20:19:34

标签: r shiny

我有一个ShinyApp,它必须在显示一组图形和数据之前计算一个很长的过程。我把它放在一个反应​​对象中执行一次操作然后在标签之间切换而不重新计算。

当反应对象工作时,如何在每个标签中添加“正在计算”框?

我试过这个,但它没有用,或者至少我不知道把标签放在哪里:

https://gist.github.com/withr/8799489

欢迎任何帮助,这是一个例子:

library("shiny")
library("shinydashboard")

shinyApp(
  ui=shinyUI(dashboardPage(skin = "blue",
                           dashboardHeader(title = "Dashboard"),
                           dashboardSidebar(
                             sliderInput("obs", "Number of observations:", 
                                         min = 10000, max = 90000, value = 50000, step = 10000)
                           ),
                           dashboardBody(
                             tabBox(
                               tabPanel("Tab 1", "This is tab number 1", tableOutput("tabData")),
                               tabPanel("Tab 2", "This is tab number 2", plotOutput("tabPlot"))
                             )
                           )
  ))
  ,
  server=shinyServer(function(input, output) {
    calculate_hist <- reactive({
      cat("Calculating for ",input$obs,"\n")
      if (is.null(input$obs)) {
        dist <- NULL
      }else{
        dist<-numeric()
        for (i in 1:input$obs) dist <- c(dist, rnorm(1))
      }
      cat("Ended\n")
      dist
    })
    output$tabPlot<-renderPlot({
      chist<-calculate_hist()
      if (is.null(chist)){
        return()
      }else{
        hist(chist, breaks = 100)
      } 
    })
    output$tabData<-renderTable({
      chist<-calculate_hist()
      if (is.null(chist)){
        return()
      }else{
        sumdata<-data.frame(n=length(chist),mean=mean(chist),var=var(chist))
        sumdata
      }
    })
  })
)

1 个答案:

答案 0 :(得分:0)

您可以使用import { SampleDataService } from '../providers/sample-data-service'; import { HttpModule} from '@angular/http'; @NgModule({ declarations: [ MyApp, HomePage, ListPage, About, Contact, AboutCity ], imports: [ BrowserModule, HttpModule, IonicModule.forRoot(MyApp) //AutoCompleteModule, ], bootstrap: [IonicApp], entryComponents: [ MyApp, HomePage, ListPage, About, Contact, AboutCity ], providers: [ StatusBar, SplashScreen, {provide: ErrorHandler, useClass: IonicErrorHandler}, SampleDataService, ] }) 包中的busyIndicator功能,并使用shinysky包中的inlineCSS覆盖其css。

这样的事情:

shinyjs

希望它有所帮助!