Disconected from server for no aparent reason

208 views
Skip to first unread message

Pedro Orozco del Pino

unread,
Jun 15, 2017, 4:40:42 PM6/15/17
to shinyapps.io Users
Hello,

I deployed an app locally and had no problems at all. But when I deploy it on the web then I get disconnected from server message every time I try to upload a file. My app depends 100% on the ability to upload files. I attached a file to so tests if you need to and I paste the code here. It is a super simple app and it is very annoying that is not working

Thanks



library(shiny)
library(XLConnect)
# library(readxl)
# library(xlsx)

# Define UI for application that draws a histogram
ui <- fluidPage(
  
  # Application title
  # br(),
  tags$body(style="background-color:white;"),
  h1("Panelist Index",style="color:#A4A4A4"),
  
  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    div( sidebarPanel(
      h3("Data Upload"),  
      fileInput("data.file", "Choose Data File"),
      
      h3("Discrimination Index"), 
      textInput("DIS.upper", "Upper Bound (default=0.5)"),
      textInput("DIS.target", "Target (default=0.01)"),
      
      h3("Repeatability Index"), 
      textInput("REP.upper", "Upper Bound (default=9)"),
      textInput("REP.target", "Target (default=1)"),
      
      h3("Agreement Index"), 
      textInput("AGR.target", "Target (default=0.95)"),
      textInput("AGR.lower", "Lower Bound (default=0.5)"),
      
      h3("Download the outputs"), 
      textInput("savefile1", "File Name"),
      downloadButton("downloadtable1", "Save Data Table to .xlsx")
      ,style="color:#6E6E6E"
      ,br()
      # ,img(width=200, height=100,src='Capture.png')
    )),
    
    # Show a plot of the generated distribution
    mainPanel(
      
      div(
        fluidRow(
          column(8,tableOutput("contents")),
          column(4,img(width=200, height=100,src='CaptureW.png')),
          column(8,plotOutput("plot")),
          style="color:#574c4c "
        )
      )
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  
  #Geometric Mean
  gm_mean = function(x, na.rm=TRUE){
    x[x==0] <- 10^(-2)
    exp(sum(log(x), na.rm=T) / length(x))
  }
  Infile <- reactive({
    inFile <- input$data.file
    
    if (is.null(inFile))
      return(NULL)
    else{
      wb = loadWorkbook(inFile$datapath)
      sheet.names <- getSheets(wb)
      l <- vector("list")
      for(i in 1:length(sheet.names)){
        l[[i]] <- readWorksheet(wb, sheet = sheet.names[i])
      }
      names(l) <- sheet.names
      return(l)}
  })
  ## Discrimination Index ##
  DIS.index.panel <- reactive({
    infile <-  Infile()[[2]]
    dim <- dim(infile)
    data.raw <- infile[2:(dim[1]-1), (-1)]
    panelist <- as.character(infile[1, -1])  # panelist
    attribute <- as.character(infile[2:(dim[1]-1), 1])  # attribute
    
    data <- matrix(NA, nrow(data.raw), ncol(data.raw))
    for(i in 1:nrow(data)){
      for(j in 1:ncol(data)){
        if(is.na(as.numeric(data.raw[i, j]))){
          if( length(grep("<", data.raw[i, j]))==1 ) data[i, j] <- as.numeric(sub("<", "", data.raw[1, 2]))/2
          else data[i, j] <- NA
        }
        else(data[i, j] <- as.numeric(data.raw[i, j]))
      }
    }
    colnames(data) <- panelist
    rownames(data) <- attribute
    # discrimination index; lower is better
    if(is.na(as.numeric(input$DIS.upper)))
      upper <- 0.5
    else upper <- as.numeric(input$DIS.upper)
    if(is.na(as.numeric(input$DIS.target)))
      target <- 0.01
    else  target <-  as.numeric(input$DIS.target)
    d <- (upper-data)/(upper-target)
    d[data>upper] <- 0  # not preferred
    d[data<target] <- 1  # most preferred
    d
  })
  
  DIS.index <- reactive({
    apply(DIS.index.panel(), 2, gm_mean, na.rm=T)
  })
  
  ## Repeatability Index ##
  REP.index.panel <- reactive({
    infile <-  Infile()[[3]]
    dim <- dim(infile)
    data.raw <- infile[2:(dim[1]-1), (-1)]
    panelist <- as.character(infile[1, -1])  # panelist
    attribute <- as.character(infile[2:(dim[1]-1), 1])  # attribute
    
    data <- matrix(NA, nrow(data.raw), ncol(data.raw))
    for(i in 1:nrow(data)){
      for(j in 1:ncol(data)){
        if(is.na(as.numeric(data.raw[i, j]))){
          if( length(grep("<", data.raw[i, j]))==1 ) data[i, j] <- as.numeric(sub("<", "", data.raw[1, 2]))/2
          else data[i, j] <- NA
        }
        else(data[i, j] <- as.numeric(data.raw[i, j]))
      }
    }
    colnames(data) <- panelist
    rownames(data) <- attribute
    # discrimination index; lower is better
    if(is.na(as.numeric(input$REP.upper)))
      upper <- 9
    else upper <- as.numeric(input$REP.upper)
    if(is.na(as.numeric(input$REP.target)))
      target <- 1
    else  target <-  as.numeric(input$REP.target)
    d <- (upper-data)/(upper-target)
    d[data>upper] <- 0  # not preferred
    d[data<target] <- 1  # most preferred
    d
  })
  
  REP.index <- reactive({
    apply(REP.index.panel(), 2, gm_mean, na.rm=T)
  })
  
  ## Agreement Index ##
  AGR.index.panel <- reactive({
    infile <-  Infile()[[4]]
    dim <- dim(infile)
    data.raw <- infile[2:(dim[1]-1), (-1)]
    panelist <- as.character(infile[1, -1])  # panelist
    attribute <- as.character(infile[2:(dim[1]-1), 1])  # attribute
    
    data <- matrix(NA, nrow(data.raw), ncol(data.raw))
    for(i in 1:nrow(data)){
      for(j in 1:ncol(data)){
        if(is.na(as.numeric(data.raw[i, j]))){
          if( length(grep("<", data.raw[i, j]))==1 ) data[i, j] <- as.numeric(sub("<", "", data.raw[1, 2]))/2
          else data[i, j] <- NA
        }
        else(data[i, j] <- as.numeric(data.raw[i, j]))
      }
    }
    colnames(data) <- panelist
    rownames(data) <- attribute
    # discrimination index; lower is better
    if(is.na(as.numeric(input$AGR.target)))
      target <- 0.95
    else target <- as.numeric(input$AGR.target)
    if(is.na(as.numeric(input$AGR.lower)))
      lower <- 0.5
    else  lower <-  as.numeric(input$AGR.lower)
    d <- (data-lower)/(target-lower)
    d[data>target] <- 1  # most preferred
    d[data<lower] <- 0  # not preferred
    d
  })
  
  AGR.index <- reactive({
    apply(AGR.index.panel(), 2, gm_mean, na.rm=T)
  })
  
  final.index <- reactive({
    exp( (4*log(DIS.index()) + 3*log(REP.index()) + 3*log(AGR.index())) / 10 )
    
  })
  
  output$contents <- renderTable({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    if(is.null(input$data.file))
      return(NULL)
    data.frame(DIS=DIS.index(), REP=REP.index(), AGR=AGR.index(), FINAL=final.index())
    
  }, include.rownames=TRUE)
  
  output$downloadtable1<-downloadHandler(
    filename = function() {paste(input$savefile1, ".xlsx", sep="")},
    content = function(file) {
      final <- data.frame(DIS=DIS.index(), REP=REP.index(), AGR=AGR.index(), FINAL=final.index())
      writeWorksheetToFile(file, data=DIS.index.panel(), sheet="DIS desirability", startRow = 1, startCol = 1, rownames = "attribute")
      writeWorksheetToFile(file, data=REP.index.panel(), sheet="REP desirability", startRow = 1, startCol = 1, rownames = "attribute")
      writeWorksheetToFile(file, data=AGR.index.panel(), sheet="AGR desirability", startRow = 1, startCol = 1, rownames = "attribute")
      writeWorksheetToFile(file, data=final, sheet="Summary", startRow = 1, startCol = 1, rownames = "attribute")
      # write.xlsx(DIS.index.panel(),file, sheetName="DIS desirability")
      # write.xlsx(REP.index.panel(),file, sheetName="REP desirability",append=TRUE)
      # write.xlsx(AGR.index.panel(),file, sheetName="AGR desirability",append=TRUE)
      # write.xlsx(final,file, sheetName="Summary",append=TRUE)
      
    }
    
  )
  output$plot<-renderPlot({
    clr<-"#336699"
    if(is.null(input$data.file)){
      par(bg="white",col.lab=clr)
      plot(0,xaxt='n',yaxt='n',bty='n',pch='',ylab='',xlab='')
      return(NULL)}
    x<-rev(final.index())
    par(bg="white",col.lab=clr,mar = c(3.1,10,1.6,2),las=2,cex=1)
    infile <-  Infile()[[4]]
    panelist <- as.character(infile[1, -1])  # panelist
    
    
    barplot(x,horiz=T,col=clr,col.axis="#574c4c",names.arg = panelist,xlim=c(0,1),cex.axis=1.25)
    abline(v=c(0.4,0.6,0.8),col=c("firebrick1","orange1","limegreen"),lwd=3,lty=2)
    
    
    
    
  })
  
  
}

# Run the application 
shinyApp(ui = ui, server = server)

Book1.xlsx

Joshua Spiewak

unread,
Jun 16, 2017, 3:53:47 PM6/16/17
to shinyapps.io Users
I have reproduced the problem and narrowed it down to the call to readWorksheet. For some reason is segmentation faulting the R process, but it isn't clear to me why. One thought would be something about R and Java.
I see that you have some alternative libraries for reading Excel files commented out, were those failing in the same way? Do all Excel files fail?

Pedro Orozco Del Pino

unread,
Jun 16, 2017, 4:08:59 PM6/16/17
to Joshua Spiewak, shinyapps.io Users
Yes, using other ways of reading the files didn't solved the problem.

Pedro 
--
You received this message because you are subscribed to a topic in the Google Groups "shinyapps.io Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shinyapps-users/a0ljyf4CuZ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/69e48420-710d-4d59-aa0a-fa72a2c5d447%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

parvane shafiei

unread,
Jun 21, 2017, 5:02:58 AM6/21/17
to shinyapps.io Users
I solved this problem by reinstalling the packages (used in the R code) by having root access therough this command:
sudo su - -c "R -e \"install.packages('packagename', repos = 'http://cran.rstudio.com/')\""

Pedro Orozco del Pino

unread,
Jun 22, 2017, 9:09:47 AM6/22/17
to shinyapps.io Users
Hi Parva, did you publish the shinny app? Could you help me translate the command to windows? I've being trying to implement your solution with no luck.

Pedro Orozco del Pino

unread,
Jun 22, 2017, 9:10:12 AM6/22/17
to shinyapps.io Users
Yes, using other ways of reading the files didn't solved the problem.

Joshua Spiewak

unread,
Jun 26, 2017, 9:30:54 AM6/26/17
to shinyapps.io Users
Do all Excel files fail?

Pedro Orozco Del Pino

unread,
Jun 26, 2017, 10:09:13 AM6/26/17
to Joshua Spiewak, shinyapps.io Users
Yes. All files fail.

Pedro 
--
You received this message because you are subscribed to a topic in the Google Groups "shinyapps.io Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shinyapps-users/a0ljyf4CuZ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.

Joshua Spiewak

unread,
Jul 6, 2017, 11:11:13 AM7/6/17
to shinyapps.io Users, j...@rstudio.com
Can you try with R 3.3.3 and let me know if that works?
To unsubscribe from this group and all its topics, send an email to shinyapps-users+unsubscribe@googlegroups.com.
To post to this group, send email to shinyapps-users@googlegroups.com.

Joshua Spiewak

unread,
Jul 13, 2017, 2:38:29 PM7/13/17
to shinyapps.io Users, j...@rstudio.com
An alternative work around is to place options(java.parameters = "-Xss2048k") before your library calls, i.e. before rJava starts Java.

Pedro Orozco del Pino

unread,
Aug 10, 2017, 4:32:33 PM8/10/17
to shinyapps.io Users, j...@rstudio.com
This worked! Sorry It took me a very long time to reply
To unsubscribe from this group and all its topics, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.

Joshua Spiewak

unread,
Oct 27, 2017, 10:50:40 AM10/27/17
to shinyapps.io Users
FYI, rJava 0.9-9 contains a fix for this issue.
Reply all
Reply to author
Forward
0 new messages