如果在spark服务器上部署时有> 152个selectInput,则闪亮的app会停止

时间:2014-08-18 20:47:48

标签: r shiny

我有一个闪亮的应用程序,在某些时候为用户上传的表数据集的每一列创建一个selectInput。当输入数据集包含152列时,将生成152个selectInput,并按预期完成进一步分析。但是,当输入文件包含153或更多列时,应用程序将开始构建selectInputs列表,但随后停止(屏幕变为灰色)。当应用程序在本地运行时,但仅当它在spark.rstudio.com托管时,才会出现此问题。我没有在日志文件中发现任何特定错误。

以下是在server.R中描述生成多个selectInputs的函数的方法:

output$selectUI<-renderUI({ 
    if (is.null(input$taxtax)) {
      return(NULL)
    }

    progress <- Progress$new(session, min=1, max=10)
    on.exit(progress$close())

    progress$set(message = 'Preparing optional adjustment of feeding types',
             detail = 'Please wait...')

    for (i in 1:10) {
      progress$set(value = i)
      Sys.sleep(0.05)
    }

    library(gdata)
    tax<-read.xls(input$taxtax$datapath,check.names=F)
    tax[,-(1:2)]<-sapply(tax[,-(1:2)],as.character)
    tax[,-(1:2)]<-sapply(tax[,-(1:2)],as.numeric)
    names(tax)[1]<-"a"
    names(tax)[2]<-"b"

    dup<-which(duplicated(names(tax))==T)

    dupl<-length(dup)

    namesl<-length(names(tax))

    if (dupl>0) {
      duplindicator<-1
      megadupset<-vector()
      for (i in 1:dupl) {
        dupset<-which(names(tax)[1:namesl]==names(tax)[dup[i]])
        megadupset<-append(megadupset,dupset)
        dupsum<-rowSums(tax[dupset])
        dupname<-names(tax)[dupset][1]
        dupsum<-cbind(dupsum)
        colnames(dupsum)<-dupname
        tax<-cbind(tax,dupsum)
      }

      tax<-tax[-megadupset]

      del<-grep(".",names(tax),fixed=T)

      if (length(del)>0) {
        tax<-tax[-del]
      }
    }

    tax<-tax[,-1]
    dat<-read.xls("database.xls")
    if (is.null(input$additem)==F){
      datadditem<-data.frame(input$additem[-1,])
      names(datadditem)<-names(dat)
      dat<-rbind(dat,datadditem)
      dat<-dat[order(as.character(dat[,1])),]
      dat[,2]<-as.integer(dat[,2])
      dat[,3]<-as.integer(dat[,3])
      dat[,4]<-as.numeric(dat[,4])
    }

    taxa<-tax[,-1]

    c<-ncol(taxa)
    i<-1
    found<-vector()
    guess<-vector()

    for (i in 1:c)
    {
      taxon<-names(taxa)[i]
      i<-i+1
      feed<-dat[dat["taxon"]==taxon][3]
      if (is.na(feed)==TRUE) {
        found.value<-taxon
        found<-append(found,found.value)
      }
    }

    if (length(found)==0) {

      c<-ncol(taxa)
      i<-1
      feedvector<-vector()

      for (i in 1:c)
      {
        taxon<-names(taxa)[i]
        if (dat[dat["taxon"]==taxon][5]=="") {
          feed<-dat[dat["taxon"]==taxon][3]
        } else {
          feed<-paste(dat[dat["taxon"]==taxon][3],dat[dat["taxon"]==taxon][5],sep="")
        }
        feedvector<-append(feedvector,feed)
        i<-i+1
      }

      # sorting
      sort<-order(substr(feedvector,1,1),names(taxa))

      i<-1
      for (i in 1:c) {
        if (feedvector[i]==1) feedvector[i]<-"Herbivores"
        if (feedvector[i]=="1a") feedvector[i]<-"Herbivores - sedentary parasites"
        if (feedvector[i]=="1b") feedvector[i]<-"Herbivores - migratory endoparasites"
        if (feedvector[i]=="1c") feedvector[i]<-"Herbivores - semi-endoparasites"
        if (feedvector[i]=="1d") feedvector[i]<-"Herbivores - ectoparasites"
        if (feedvector[i]=="1e") feedvector[i]<-"Herbivores - epidermal/root hair     feeders"
        if (feedvector[i]=="1f") feedvector[i]<-"Herbivores - algal/lichen/moss feeders"
        if (feedvector[i]==2) feedvector[i]<-"Fungivores"
        if (feedvector[i]==3) feedvector[i]<-"Bacterivores"
        if (feedvector[i]==5) feedvector[i]<-"Predators"
        if (feedvector[i]==7) feedvector[i]<-"Animal parasites (dispersal stages)"
        if (feedvector[i]==8) feedvector[i]<-"Omnivores"
      }

      x<-length(feedvector)
      outputlist<-list()
      i<-1

      for (i in sort) {
        output<-selectInput(paste("feed",i,sep=""), colnames(taxa)[i], 
                            c("Herbivores - sedentary parasites"="1a","Herbivores - migratory endoparasites"="1b","Herbivores - semi-endoparasites"="1c","Herbivores - ectoparasites"="1d","Herbivores - epidermal/root hair feeders"="1e","Herbivores - algal/lichen/moss feeders"="1f","Fungivores"=2,"Bacterivores"=3,"Predators"=5,"Animal parasites (dispersal stages)"=7,"Omnivores"=8),
                            selected=feedvector[i])
        outputlist<-append(outputlist,output)
      }

      outputlist

    } else {return(NULL)}

  })

ui.R中的对应行:

htmlOutput(selectUI)

0 个答案:

没有答案