R Shiny在本地工作,但不在服务器上工作

时间:2019-11-28 01:37:05

标签: r shiny shinyapps

我已经安装了所有库依赖项,当我运行is.shiny.appobj(shinyApp(ui,server))时,它返回TRUE。

我确实有一些正在调用的文件,但它们的格式为"file.csv",根据我的研究,该文件旨在为您提供帮助。

确切的错误消息:app.R did not return a shiny.appobj object.

我要执行的操作的基本原理是调用一个文件,通过其他一些文件运行它以获取输出,然后以更新的格式和一些新值返回原始文件。我还添加了当您选择行时使用DT包添加一列的功能。

这是我带库的UI代码:

library(shiny)
library(rsconnect)
library(lubridate)
library(dbplyr)
library(dplyr)
library(tidyr)
library(readr)
library(DT)

ui=fluidPage(
  fileInput(inputId = "bill",label="Select Bill"), #choose bill
  downloadLink("downloadbill", "Download Bill"),
  hr(),
  h5("Total for Selected Rows :"),
  textOutput("dateTotal"),
  DT::dataTableOutput('table')
)

这是我的服务器代码:

server<-function(input,output){
  observe({
    req(input$bill)


    ####Load in CSV files####

    drugs=read.csv("updateddrugs.csv")
    #loading similar files

    ####Find code in row input####

    findcode<- function (rowinput) {
      column7.output=""
      if (as.character(rowinput[1])!=""){
        code=as.character(rowinput[3])
        codedate=substr(as.character(rowinput[1]),1,10)
        units=as.character(rowinput[6])
        charges=as.character(rowinput[7])
        column7.output=OMFS(codedate,code,units,charges)}
      return(column7.output)
    }

    ####OMFS type####

    OMFS <-function (codedate,code,units,charges) {
      parsed.date<-mdy(codedate)
      OMFS.amount=0.00
      OMFS.temp=0.00
      if (startsWith(code,"99070")){ #drug code
        OMFS.temp=search.drugs(code)

        if(nchar(OMFS.temp)==0){
          OMFS.amount=parse_number(charges)
        }
        else{
          OMFS.amount=OMFS.temp
        }
        return(OMFS.amount)
      }
      else{

        if(startsWith(code,"ML") | startsWith(code, "ml")){ #med legal code
          OMFS.amount=parse_number(charges)
        }
        else{
          if(startsWith(code,"WC")|startsWith(code,"wc")){
            if (year(parsed.date)>2013){
              if (year(parsed.date)==2014){
                OMFS.amount=wcprice$X2014[wcprice$code==code]
              }
              if (year(parsed.date)==2015){
                OMFS.amount=wcprice$X2015[wcprice$code==code]
              }
              if (year(parsed.date)==2016){
                OMFS.amount=wcprice$X2016[wcprice$code==code]
              }
              if (year(parsed.date)==2017){
                OMFS.amount=wcprice$X2017[wcprice$code==code]
              }
              if (year(parsed.date)==2018){
                OMFS.amount=wcprice$X2018[wcprice$code==code]
              }
              if (year(parsed.date)==2019){
                OMFS.amount=wcprice$X2019[wcprice$code==code]
              }
            }
          }

          else{
            OMFS.temp=search.OMFS(parsed.date,substr(code,1,5),units)
            if(is.na(OMFS.temp)||nchar(OMFS.temp)==0 || OMFS.temp==0.00){
              OMFS.amount=parse_number(charges)
            }
            else{
              OMFS.amount=OMFS.temp
            }
          }}
        return(OMFS.amount)
      }

    }


    ####searching for OMFS is CSV files####

    search.OMFS<-function(codedate,code,units){
      pre2014span<-seq.Date(from=as_date("2000-01-01"),to=as_date("2013-12-31"),by="day")
      weird2007span<-seq.Date(from=as_date("2007-02-15"),to=as_date("2013-12-31"),by="day")
      #and similar spans

      if (codedate %in% pre2014span){
        if(code %in% blood$V1){
          price=blood[blood$V1==code,2]
          price2=price*as.numeric(units)
        }

        else{
          if (codedate %in% weird2007span & code %in% weird2007codes$V1){
            price=weird2007codes[weird2007codes$V1==code,2]
            price2=price*as.numeric(units)
          }
          else{
            price=OMFS2003 %>% filter(V2==code) %>% select(V7)
            price=as.numeric(as.character(price[[1]]))
            if (length(price>1)){price=max(price)}
            units=as.numeric(units)
            price2=price*units
            }

        }
        return(as.character(price2))
      }
      #similar conditional statements for span dates
    }

    ####searching for drug codes####

    search.drugs <-function(code){ #OMFS for drugs
      smallcode=gsub(".*-","",code)
      price=drugs %>% filter(Column2==smallcode) %>% select(PRICE)
      price=as.numeric(as.character(price[[1]]))
      return(price)
    }

    ####payments####
    paymentsmade<-function(bill,CalculatedOMFSColumn){
      for (i in 1: nrow(bill)){
        if (startsWith(as.character(bill[i,7]),"($")){
          CalculatedOMFSColumn[i]=parse_number(as.character(bill[i,7]))*-1
        }
      }
      return(CalculatedOMFSColumn)
    }

    ###################
    ####loadingbill####

    tempbill=(input$bill) #call in bill

    showModal(modalDialog("Please wait while your bill is processing.", footer=NULL)) #starting loading message

    bill=read.csv(tempbill$datapath,colClasses = "character") #read bill
    smallerbill=bill[,1:15]
    smallerbill<-as.data.frame(smallerbill)
    payments=(smallerbill[,10:15])
    charges=(smallerbill[,1:9])

    newnames<-c("X.1","X.2","X.3","X.4","X.6","X.7")
    colnames(payments)<-newnames
    payments$ID<-seq.int(nrow(payments))
    payments$X.5<-c("")
    payments$X.8<-c("")
    payments$X<-c("")

    charges$ID<-seq.int(nrow(charges))

    newbill<-rbind(payments,charges)

    newbill<-arrange_at(newbill,"ID")
    newbill1<-newbill[,order(colnames(newbill))]
    newbill1$ID<-NULL

    newbill1$X.8<-NULL

    colnamesbill<-c("DOS","DOE","Procedue","Modifier","Description","Unit","Charges","Total Charges")

    colnames(newbill1)<-colnamesbill

    newbill1<-newbill1 %>% filter(Charges!="")


    OMFSColumn<-apply(newbill1,1,findcode) #generate OMFS column

    updatedwithPayments<-paymentsmade(newbill1,OMFSColumn)

    updatedwithPay<-vapply(updatedwithPayments,paste, collapse=",", character(1L))

    newbill1$OMFS=updatedwithPay

    outputbill<-renderDataTable(newbill1)
    removeModal() #remove loading message

    output$table<-outputbill

    output$dateTotal=renderText({ #outputs the total for the selected rows
      s=input$table_rows_selected
      return(sum(as.numeric(newbill1[s,9])))

    })

    output$downloadbill<-downloadHandler(
      filename = "patientname.csv",
      content = function(filename) {
        write.csv(newbill1, filename, row.names = FALSE)
      }
    )
  })
}
shinyApp(ui=ui,server = server)

我愿意接受任何建议!

1 个答案:

答案 0 :(得分:0)

感谢@HubertL,将服务器和ui拆分是答案。如果人们有其他解决方案,我很高兴听到他们的声音!