Adding a new reactive variable to a dataframe to calculate cosine similarity

I want to create a Shiny App.
Main components of the Shiny App: textAreaInput and tableOutput
Main purpose of the Shiny App: A user would write a textstring into the textField and measured by this textstring the tableOut will display some rows of text from my dataframe which i load into the App.

Therefore i want to calculate cosine similarity between the textstrings. If similarity is greater than let's say .75 the text will be displayed.

The dataset in the background is a simple dataframe with one variable text and some rows of text observations, like this:

df = tibble(TEXT=c("text one", 
"text two", 
"text three", 
"text four", 
"text five"))

# A tibble: 5 x 1
1 text one  
2 text two  
3 text three
4 text four 
5 text five

My idea was to reactively add a new variable to that dataframe ... with something like...

textAreaInput(inputId = "query", label = "Query", resize = "vertical")

df_reactive = reactive({
df$QUERY = input$query

... to get something like.. to then calculate the similarity

# A tibble: 5 x 2
  TEXT       QUERY      
  <chr>      <chr>      
1 text one   input$QUERY
2 text two   input$QUERY
3 text three input$QUERY
4 text four  input$QUERY
5 text five  input$QUERY

Homever i cannot get this reactive() function to work. Maybe there is a general better solution to this..Any suggestions?

At all: when i look up some topics at, the search engine recommends me some topics. How are these recommendations calculated?


df_reactive = reactive({
   dfnew <- df
   dfnew$QUERY = req(input$query)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.