title: Function that feeds into shiny app runs without errors but does not produce objects
body: <p>I created this function to use in a shiny app. It will allow the user to select one of two choice buttons to determine which dataset is displayed in a word cloud.</p>
  <p>The code runs fine when I run it outside of the function, but the function does not produce any objects when I run it.</p>
  <p>I created this code based on the Shiny website's wordcloud tutorial: <a href="https://shiny.rstudio.com/gallery/word-cloud.html" rel="nofollow noreferrer">https://shiny.rstudio.com/gallery/word-cloud.html</a></p>
  <p>Thanks for your ideas!</p>
  <pre><code>library(tidyverse)
  library(NLP)
  library(tm)
  library(wordcloud)
  library(memoise)
  library(tidyverse)
  library(stringr)
  library(ltm)
  library(tm)
  library(glue)
  
  food_purchasing &lt;- read_csv(&quot;food_purchasing_wordcloud.csv&quot;)
  
  # Using &quot;memoise&quot; to automatically cache the results
  getTermMatrix &lt;- memoise(function(choice) {
    
    # Input your choice - generate df to generate word cloud
    if (choice == &quot;First&quot;)
        { first_impression &lt;- food_purchasing%&gt;%
            mutate(localimpression_first = tolower(localimpression_4)) %&gt;%
            dplyr::select(ResponseId, localimpression_first)
          
          # Create a corpus
          first_corpus &lt;- Corpus(VectorSource(first_impression))
          
          # Clean the text
          first &lt;- first_corpus %&gt;%
            tm_map(removeNumbers) %&gt;%
            tm_map(removePunctuation) %&gt;%
            tm_map(stripWhitespace)
          first &lt;- tm_map(first, content_transformer(tolower))
          first &lt;- tm_map(first, removeWords, stopwords(&quot;english&quot;))
          
          # Create document term matrix for making word cloud
          dtm_first &lt;- TermDocumentMatrix(first) 
          matrix_first &lt;- as.matrix(dtm_first) 
          words_first &lt;- sort(rowSums(matrix_first),decreasing=TRUE) 
          wordcloud_df &lt;- data.frame(word = names(words_first),freq=words_first)
          
          }
        
        else {
      
          food_purchasing$localimpression_any &lt;- food_purchasing %&gt;%
            glue_data(&quot;{localimpression_4}; {localimpression_5}; {localimpression_6}&quot;)
          
          any_impression &lt;- food_purchasing %&gt;%
            dplyr::select(localimpression_any) %&gt;%
            str_to_lower() %&gt;%
            str_trim()
          
          # Create a corpus
          any_corpus &lt;- Corpus(VectorSource(any_impression))
          
          # Clean the text
          any &lt;- any_corpus %&gt;%
            tm_map(removeNumbers) %&gt;%
            tm_map(removePunctuation) %&gt;%
            tm_map(stripWhitespace)
          any &lt;- tm_map(any, content_transformer(tolower))
          any &lt;- tm_map(any, removeWords, stopwords(&quot;english&quot;))
          
          # Create document term matrix
          dtm &lt;- TermDocumentMatrix(any) 
          matrix &lt;- as.matrix(dtm) 
          words &lt;- sort(rowSums(matrix),decreasing=TRUE) 
          wordcloud_df &lt;- data.frame(word = names(words),freq=words)
        }
  })```
  </code></pre>