首页 > 解决方案 > 单词预测应用程序使用了太多闪亮的内存?

问题描述

对于我在 JHU Capstone 项目的 Word Prediction Shiny APP 代码中遇到的问题,我将非常感谢社区可能提供的任何反馈。

server.R 和 UI.r 代码在本地正确运行。当我上传到 shinyapps.io 时,我的内存不足。我在下面提供了服务器和 UI 代码以及来自 Shiny 的日志。

怀疑的根本原因:我认为问题在于用于创建语料库和预测功能的大型文本文件......它们也正在上传到闪亮。

我怀疑我需要通过在创建 corpus_train编写不需要它们的代码来排除大型 txt 文件上传到闪亮。

我的假设正确吗?如果是这样,我该如何将其写入我的代码?或者,我是不是不在基地,还有另一种解决方案?

我尝试过的事情:

  1. 在为语料库设置子集后在代码中编写 rm(原始文本文件):这导致应用程序失败,因为它正在寻找这些文件(en_US.blogs.txt、en_US.twitter.txt、en_US.news 。文本)
  2. 写入 rm(除 "corpus_train" 之外的所有文件 - 用于预测 这导致应用程序失败,因为它不仅要查找 #1 中提到的大 txt 文件,还要查找 combine_sample 和 twit/news/blog 样本文件
  3. 创建一个仅包含 APP 及其环境的新项目。
  4. 在 Stackflow 上阅读了许多类似的问题,但没有看到可以应用于我的情况的问题。

非常感谢社区的帮助!


    ui.R
    library(shiny)
    library(sbo)
    library(processx)
    
    
    
    shinyUI(pageWithSidebar(
            
            headerPanel("Predicitve Text APP"),
            sidebarPanel(
                    textInput("text", label = h3("Text input"), value = "Enter text..."),
                    
                    
                    
            ),
            
            mainPanel(
                    h4("Predicted Words:"),
                    verbatimTextOutput("result_output"),
    
                    
                    
                    h6("This APP generates three predicted next words based on the text you input. 
                       The prediction algorithm relies on word frequencies in the English twitter, 
                       blogs, and news datasets at:"),
                    h6(a("http://www.corpora.heliohost.org/")),
                    br(),
                    h6("Created April 2021 as part of my Captsone project for the 
                    Data Science Specialization provided by Johns Hopkins University and Coursera.
                    All code can be located on GitHub at:") ,
                    h6(a("https://github.com/themonk99/predictive.git"))
                    
            )
            
            
    ))
    ```server.r
    ##setwd("C:/Users/themo/OneDrive/Data Science JHU/Capstone/RHays_Shiny_Capstone")
    
    blog <- readLines("en_US.blogs.txt", warn=FALSE, encoding="UTF-8")
    twit <- readLines("en_US.twitter.txt", warn=FALSE, encoding="UTF-8")  
    news <- readLines("en_US.news.txt", warn=FALSE, encoding="UTF-8")
    
    twit_sample <- sample(twit, length(twit)*.10)
    news_sample <- sample(news, length(news)*.10)
    blog_sample <- sample(blog, length(blog)*.10)
    
    combined_sample <- c(twit_sample, blog_sample, news_sample)
    combined_sample <- iconv(combined_sample, "UTF-8","ASCII", sub="")
    length(combined_sample)
    
    
    corpus_train <- sbo_predictor(object = combined_sample, 
                                  N = 3, 
                                  dict = target ~ 0.75,
                                  .preprocess = sbo::preprocess,  
                                  EOS = ".?!:;", 
                                  lambda = 0.4, 
                                  L = 3L, 
                                  filtered = 
    )
    
    
    
    
    
    
    server <- function(input, output) {
            
            output$result_output <-renderText({
                    predict(corpus_train,input$text)
            })
    }
    
    ```

    2021-04-29T11:23:10.973363+00:00 shinyapps[4050847]: httpuv version: 1.5.5
    2021-04-29T11:23:10.973342+00:00 shinyapps[4050847]: shiny version: 1.6.0
    2021-04-29T11:23:10.973399+00:00 shinyapps[4050847]: rmarkdown version: (none)
    2021-04-29T11:23:10.973407+00:00 shinyapps[4050847]: knitr version: (none)
    2021-04-29T11:23:10.973412+00:00 shinyapps[4050847]: jsonlite version: 1.7.2
    2021-04-29T11:23:10.973442+00:00 shinyapps[4050847]: RJSONIO version: (none)
    2021-04-29T11:23:10.973312+00:00 shinyapps[4050847]: Server version: 1.8.6.1
    2021-04-29T11:23:10.973449+00:00 shinyapps[4050847]: htmltools version: 0.5.1.1
    2021-04-29T11:23:10.973617+00:00 shinyapps[4050847]: Using pandoc: /opt/connect/ext/pandoc/2.11
    2021-04-29T11:23:11.175095+00:00 shinyapps[4050847]: Using jsonlite for JSON processing
    2021-04-29T11:23:11.179051+00:00 shinyapps[4050847]: 
    2021-04-29T11:23:11.179052+00:00 shinyapps[4050847]: Starting R with process ID: '209'
    2021-04-29T11:23:11.212694+00:00 shinyapps[4050847]: 
    2021-04-29T11:23:11.212696+00:00 shinyapps[4050847]: Listening on http://127.0.0.1:42961
    2021-04-29T11:23:31.691484+00:00 shinyapps[system]: Out of memory!
    2021-04-29T11:23:34.451176+00:00 shinyapps[4050847]: Running on host: 6c927e59cf13
    2021-04-29T11:23:34.456391+00:00 shinyapps[4050847]: R version: 4.0.2
    2021-04-29T11:23:34.456489+00:00 shinyapps[4050847]: knitr version: (none)
    2021-04-29T11:23:34.456381+00:00 shinyapps[4050847]: Server version: 1.8.6.1
    2021-04-29T11:23:34.456391+00:00 shinyapps[4050847]: LANG: en_US.UTF-8
    2021-04-29T11:23:34.456490+00:00 shinyapps[4050847]: jsonlite version: 1.7.2
    2021-04-29T11:23:34.456397+00:00 shinyapps[4050847]: shiny version: 1.6.0
    2021-04-29T11:23:34.456417+00:00 shinyapps[4050847]: httpuv version: 1.5.5
    2021-04-29T11:23:34.641854+00:00 shinyapps[4050847]: Using jsonlite for JSON processing
    2021-04-29T11:23:34.645882+00:00 shinyapps[4050847]: Starting R with process ID: '233'
    2021-04-29T11:23:34.645881+00:00 shinyapps[4050847]: 
    2021-04-29T11:23:34.456457+00:00 shinyapps[4050847]: rmarkdown version: (none)
    2021-04-29T11:23:34.456510+00:00 shinyapps[4050847]: htmltools version: 0.5.1.1
    2021-04-29T11:23:34.675822+00:00 shinyapps[4050847]: 
    2021-04-29T11:23:34.456510+00:00 shinyapps[4050847]: RJSONIO version: (none)
    2021-04-29T11:23:34.456666+00:00 shinyapps[4050847]: Using pandoc: /opt/connect/ext/pandoc/2.11
    2021-04-29T11:23:34.675824+00:00 shinyapps[4050847]: Listening on http://127.0.0.1:41970
    2021-04-29T11:23:54.728500+00:00 shinyapps[system]: Out of memory!
    2021-04-29T11:38:45.935720+00:00 shinyapps[4050847]: Running on host: 6c927e59cf13
    2021-04-29T11:38:45.941654+00:00 shinyapps[4050847]: Server version: 1.8.6.1
    2021-04-29T11:38:45.941664+00:00 shinyapps[4050847]: LANG: en_US.UTF-8
    2021-04-29T11:38:45.941694+00:00 shinyapps[4050847]: shiny version: 1.6.0
    2021-04-29T11:38:45.941669+00:00 shinyapps[4050847]: R version: 4.0.2
    2021-04-29T11:38:45.941744+00:00 shinyapps[4050847]: rmarkdown version: (none)
    2021-04-29T11:38:46.147771+00:00 shinyapps[4050847]: 
    2021-04-29T11:38:45.941756+00:00 shinyapps[4050847]: jsonlite version: 1.7.2
    2021-04-29T11:38:46.181887+00:00 shinyapps[4050847]: 
    2021-04-29T11:38:45.941755+00:00 shinyapps[4050847]: knitr version: (none)
    2021-04-29T11:38:45.941947+00:00 shinyapps[4050847]: Using pandoc: /opt/connect/ext/pandoc/2.11
    2021-04-29T11:38:45.941703+00:00 shinyapps[4050847]: httpuv version: 1.5.5
    2021-04-29T11:38:45.941788+00:00 shinyapps[4050847]: htmltools version: 0.5.1.1
    2021-04-29T11:38:45.941781+00:00 shinyapps[4050847]: RJSONIO version: (none)
    2021-04-29T11:38:46.143977+00:00 shinyapps[4050847]: Using jsonlite for JSON processing
    2021-04-29T11:38:46.181888+00:00 shinyapps[4050847]: Listening on http://127.0.0.1:35991
    2021-04-29T11:38:46.147772+00:00 shinyapps[4050847]: Starting R with process ID: '486'
    2021-04-29T11:39:06.539298+00:00 shinyapps[system]: Out of memory!

标签: rmemoryshiny

解决方案


推荐阅读