My shiny app works locally, but I keep getting 'Disconnected from server error' on shinyapps.io. I don't have any errors in my log. See below. Please help.
Successfully deployed to https://h-town1906.shinyapps.io/next-word-predictor/
rsconnect::showLogs("./Next-Word-Predictor")
2025-01-06T20:58:29.702735+00:00 shinyapps[13661166]: Running on host: 4ef1f36fa509
2025-01-06T20:58:29.707285+00:00 shinyapps[13661166]: Running as user: uid=10001(shiny) gid=10001(shiny) groups=10001(shiny)
2025-01-06T20:58:29.711746+00:00 shinyapps[13661166]: Connect version: 2024.05.0
2025-01-06T20:58:29.715858+00:00 shinyapps[13661166]: LANG: C.UTF-8
2025-01-06T20:58:29.720474+00:00 shinyapps[13661166]: Working directory: /srv/connect/apps/next-word-predictor
2025-01-06T20:58:29.725093+00:00 shinyapps[13661166]: Using R 4.4.2
2025-01-06T20:58:29.729394+00:00 shinyapps[13661166]: R.home(): /opt/R/4.4.2/lib/R
2025-01-06T20:58:29.733822+00:00 shinyapps[13661166]: Content will use current R environment
2025-01-06T20:58:29.738292+00:00 shinyapps[13661166]: R_LIBS: (unset)
2025-01-06T20:58:29.742612+00:00 shinyapps[13661166]: .libPaths(): /usr/lib/R, /opt/R/4.4.2/lib/R/library
2025-01-06T20:58:29.746998+00:00 shinyapps[13661166]: shiny version: 1.9.1
2025-01-06T20:58:29.751620+00:00 shinyapps[13661166]: httpuv version: 1.6.15
2025-01-06T20:58:29.756387+00:00 shinyapps[13661166]: rmarkdown version: 2.29
2025-01-06T20:58:29.760458+00:00 shinyapps[13661166]: knitr version: 1.49
2025-01-06T20:58:29.764789+00:00 shinyapps[13661166]: jsonlite version: 1.8.9
2025-01-06T20:58:29.769310+00:00 shinyapps[13661166]: RJSONIO version: (none)
2025-01-06T20:58:29.773615+00:00 shinyapps[13661166]: htmltools version: 0.5.8.1
2025-01-06T20:58:29.778552+00:00 shinyapps[13661166]: reticulate version: (none)
2025-01-06T20:58:29.783147+00:00 shinyapps[13661166]: Using pandoc: /opt/connect/ext/pandoc/2.16
2025-01-06T20:58:30.713551+00:00 shinyapps[13661166]:
2025-01-06T20:58:30.718028+00:00 shinyapps[13661166]: Starting R with process ID: '56'
2025-01-06T20:58:30.722377+00:00 shinyapps[13661166]: Shiny application starting ...
2025-01-06T20:58:30.727115+00:00 shinyapps[13661166]:
2025-01-06T20:58:30.731728+00:00 shinyapps[13661166]: Listening on http://127.0.0.1:34969
2025-01-06T20:58:31.702898+00:00 shinyapps[13661166]: ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
2025-01-06T20:58:31.708119+00:00 shinyapps[13661166]: dplyr 1.1.4 readr 2.1.5
2025-01-06T20:58:31.712532+00:00 shinyapps[13661166]: forcats 1.0.0 stringr 1.5.1
2025-01-06T20:58:31.716922+00:00 shinyapps[13661166]: ggplot2 3.5.1 tibble 3.2.1
2025-01-06T20:58:31.721263+00:00 shinyapps[13661166]: lubridate 1.9.3 tidyr 1.3.1
2025-01-06T20:58:31.727718+00:00 shinyapps[13661166]: purrr 1.0.2
2025-01-06T20:58:31.732320+00:00 shinyapps[13661166]: ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
2025-01-06T20:58:31.737899+00:00 shinyapps[13661166]: dplyr::filter() masks stats::filter()
2025-01-06T20:58:31.742611+00:00 shinyapps[13661166]: dplyr::lag() masks stats::lag()
2025-01-06T20:58:31.748883+00:00 shinyapps[13661166]: Use the conflicted package (http://conflicted.r-lib.org/) to force all conflicts to become errors
2025-01-06T20:58:32.712194+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.716616+00:00 shinyapps[13661166]: Attaching package: ‘data.table’
2025-01-06T20:58:32.721361+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.726043+00:00 shinyapps[13661166]: The following objects are masked from ‘package:lubridate’:
2025-01-06T20:58:32.730369+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.734550+00:00 shinyapps[13661166]: hour, isoweek, mday, minute, month, quarter, second, wday, week,
2025-01-06T20:58:32.738923+00:00 shinyapps[13661166]: yday, year
2025-01-06T20:58:32.743248+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.748051+00:00 shinyapps[13661166]: The following objects are masked from ‘package:dplyr’:
2025-01-06T20:58:32.752452+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.756700+00:00 shinyapps[13661166]: between, first, last
2025-01-06T20:58:32.760933+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.765379+00:00 shinyapps[13661166]: The following object is masked from ‘package:purrr’:
2025-01-06T20:58:32.769970+00:00 shinyapps[13661166]:
2025-01-06T20:58:32.774595+00:00 shinyapps[13661166]: transpose
2025-01-06T20:58:32.778777+00:00 shinyapps[13661166]:
My server.R code is as follows:
library(tidyverse)
library(tidytext)
library(stringr)
library(textclean)
library(data.table)
#======== Define server logic required to predict text
shinyServer(function(input, output) {
#saveRDS(bigram_freq, "./Next-Word-Predictor/data/bigram_freq.RDS")
bigram_freq <- readRDS("bigram_freq.RDS")
# N-gram frequency tables
#trigrams <- readRDS("./trigrams.RDS")
# Function for next-word prediction
predict_next_word <- function(input_text, ngram_freq, n) {
# Tokenize input text into n-grams of size n-1
tokens <- unnest_tokens(tibble(text = input_text), output = "ngram", input = "text", token = "ngrams", n = n - 1)
# Get the last n-1 words
last_ngram <- tokens$ngram[length(tokens$ngram)]
# Filter the n-gram frequency table for matches
predicted <- ngram_freq %>%
filter(str_starts(ngram, paste0(last_ngram, " "))) %>%
arrange(desc(n)) %>%
slice_head(n=3) # Select the top 3 predictions
# Extract only the next words
predicted_words <- predicted %>%
mutate(next_word = str_extract(ngram, paste0("(?<=", last_ngram, " ).*"))) %>%
pull(next_word)
# Return the top next words
predicted_words
}
#========= END OF TEXT PREDICTOR FUNCTION ================
Text.pred <- reactive({
userInputText <- input$Text1
predict_next_word(userInputText, bigram_freq, 2)
})
# Function waits for Submit button to be pressed prior to computing next word.
output$pred1 <- renderText({
Text.pred()
})
})