Shiny App not responding

22 views
Skip to first unread message

Jagan Mohan Rao Narayanam

unread,
Jun 28, 2016, 1:18:09 AM6/28/16
to Shiny - Web Framework for R
I deployed a very simple app on shiny server with out any issues. The app is running very much fine locally. I could load the app from server, but its not responding to the queries. I don't find any errors in the logs. I read here in this group this might be due to the size of the data files. So I took a basic plan which can provide me up to 8GB. But still same problem. I tried changing the location of data files and also tried different data files (RData or CSV)

System details: Windows 10, 64 bit, 8GB RAM

Here is my code:
global.r

library(shiny)
library(bit64)
library(data.table)
library(quanteda)
library(memoise)

load("./data/uni_dict.RData", envir=.GlobalEnv)
load("./data/unigram_dt.RData", envir=.GlobalEnv)
load("./data/bigram_dt.RData", envir=.GlobalEnv)
load("./data/trigram_dt.RData", envir=.GlobalEnv)
load("./data/tetragram_dt.RData", envir=.GlobalEnv)



server.r:


source("model.R")

shinyServer(
  function(input, output) {
    output$query <- renderPrint({input$query})
    
    output$nextwords <- renderPrint({tetragramModel(input$query)})
      }
  )

ui.r:
library(shiny)

shinyUI(fluidPage
        # Application Title
        (titlePanel("Next Word Prediction"),
        sidebarLayout(
          sidebarPanel(
            textInput(inputId = "query", 
                        label = "Enter the Text"),
            submitButton("Submit"),
            conditionalPanel(
              condition = "submitButton$Submit == TRUE")
            ),
            
        mainPanel(
          h4("Query Sentence"),
          verbatimTextOutput("query"),
          h4("Suggested Words"),
          verbatimTextOutput("nextwords")
              
          )
        )
    )
)

model.r:

tetragramModel <- memoise(function(s){
  matches = uni_dict[1:3]
  query_corpus <- corpus(s)
  query_tokens <- quanteda::tokenize(toLower(query_corpus), ngrams = 1, removeNumbers=TRUE, removePunct=TRUE, 
                                     removeTwitter = TRUE, removeSeparators = TRUE)
  
  l = length(query_tokens[[1]])
  if (l >= 3){
    query_tokens <- tail(query_tokens[[1]], 3)
    if(!FALSE %in% (query_tokens %chin% names(uni_dict))){
      query <- uni_dict[query_tokens]
      query <- as.numeric(paste0(query[1],query[2], query[3]))
      matches <- subset(tetragram_dt, trigram_int == query, select = word)[[1]]
      if (!FALSE %in% (query_tokens[2:3] %chin% names(uni_dict)) && length(matches) < 3){
        query <- uni_dict[query_tokens[2:3]]
        query <- as.numeric(paste0(query[1],query[2]))
        matches <- c(matches, subset(trigram_dt, bigram_int == query, select = word)[[1]])
        if (!FALSE %in% (query_tokens[3] %chin% names(uni_dict)) && length(matches) < 3){
          query <- as.numeric(paste0(uni_dict[[query_tokens[3]]]))
          matches <- c(matches, subset(bigram_dt, unigram_int == query, select = word)[[1]])
        }
      }
    }
    else{
      matches <- unigram_dt$word[3]
    }
  }
  else if (l == 2){
    query_tokens <- tail(query_tokens[[1]], 2)
    if(!FALSE %in% (query_tokens %chin% names(uni_dict))){
      query <- uni_dict[query_tokens]
      query <- as.numeric(paste0(query[1],query[2]))
      matches <- subset(trigram_dt, bigram_int == query, select = word)[[1]]
      if (!FALSE %in% (query_tokens[2] %chin% names(uni_dict)) && length(matches) < 3){
        query <- as.numeric(paste0(uni_dict[[query_tokens[2]]]))
        matches <- c(matches, subset(bigram_dt, unigram_int == query, select = word)[[1]])
      }
    }
    else{
      matches <- unigram_dt$word[2]
    }
  }
  else if(l == 1){
    query_tokens <- tail(query_tokens[[1]], 1)
    if (!FALSE %in% (query_tokens %chin% names(uni_dict))){
      query <- as.numeric(paste0(uni_dict[[query_tokens]]))
      matches <- subset(bigram_dt, unigram_int == query, select = word)[[1]]
    }
    else{
      matches <- uni_dict[1:3]
    }
  }
  if(length(matches)> 0 && length(matches) <=5){
    nextWords <- unique(names(uni_dict[matches]))
    #nextWords <- nextWords[2]
  }
  else if (length(matches) > 5){
    nextWords <- unique(names(uni_dict[matches]))[1:5]
  }
  else {
    nextWords <- "Sorry, couldn't find the suitable next word! \n Please Enter the Text"
  }
  return (nextWords)
})

I have no idea why its not responding. I strongly believe that the data files are not loading on the server. but no idea why they are not.

I really appreciate your help and support in this regard.

thanks and best regards,
Jagan.


Reply all
Reply to author
Forward
0 new messages