Reputation: 1
Text Analytics into big 5 personality traits(O,C,E,A,N)
Here I want the text to process when the user clicks Update View button. Then that text will be stored in "sentence" variable, then cleaning the corpus, loading the wordlist files for each of the personality trait, matching th etex input with wordlist, summing the personality scores & displaying the score & the trait user has scored high
library(shiny)
library(purrr)
library(dplyr)
library(plyr)
library(stringr)
#Analysing text entered by the user
function(input, output,session) {
textAnalysis <- eventReactive(input$update,{
function(textdata){
sentence <- input$textdata
word.list <- str_split(sentence,"\\s+")
words <- unlist(word.list)
sentence <- gsub('[[:punct:]]', "", sentence) #gsub is global substitution from stringr library
sentence <- gsub('[[:cntrl:]]', "", sentence) #cntrl are control words
sentence <- gsub('\\d+', "", sentence) #d is substituting digits with null
sentence <- tolower(sentence)
#Include word list in environment
o.words = scan("F:/MTech_Project/OpenEnd/OpennessWordList.txt", what='character',comment.char = ";")
c.words = scan("F:/MTech_Project/OpenEnd/ConscientiousnessWordList.txt", what='character',comment.char = ";")
e.words = scan("F:/MTech_Project/OpenEnd/ExtraversionWordList.txt", what='character',comment.char = ";")
a.words = scan("F:/MTech_Project/OpenEnd/AgreeablenessWordList.txt", what='character',comment.char = ";")
n.words = scan("F:/MTech_Project/OpenEnd/NeuroticismWordList.txt", what='character',comment.char = ";")
o.matches <- match(words,o.words)
c.matches <- match(words,c.words)
a.matches <- match(words,e.words)
e.matches <- match(words,a.words)
n.matches <- match(words,n.words)
o.matches <- !is.na(o.matches)
c.matches <- !is.na(c.matches)
e.matches <- !is.na(e.matches)
a.matches <- !is.na(a.matches)
n.matches <- !is.na(n.matches)
o.score <- sum(o.matches)
#o.score
c.score <- sum(c.matches)
#c.score
e.score <- sum(e.matches)
#e.score
a.score <- sum(a.matches)
#a.score
n.score <- sum(n.matches)
#n.score
score <- max(o.score,c.score,e.score,a.score,n.score)
return(score)
}}, ignoreNULL = FALSE)
output$value <- renderPrint({
textdata <- textAnalysis()
})
}
Here I am trying to take text input from the user & calling "value" in server.r
library(shiny)
fluidPage(
# Application title.
titlePanel("Text Analytics"),
sidebarLayout(
sidebarPanel(
textInput("textdata",label = "Tell something about you..what you are..what you like",""),
actionButton("update", "Update View")
),
mainPanel(
verbatimTextOutput("value"),
)))
I am stuck with how to pass the text to server.r & how to get the result displayed in ui.r Please help
Listening on http://127.0.0.1:5547
Warning: Error in tag: argument is missing, with no default
Stack trace (innermost first):
52: tag
51: tags$div
50: div
49: mainPanel
48: sidebarLayout
47: tag
46: tags$div
45: div
44: tagList
43: attachDependencies
42: bootstrapPage
41: fluidPage
1: runApp
Error : argument is missing, with no default
How do I resolve it? Please help
Upvotes: 0
Views: 830
Reputation: 35
renderUI()
can be used to get UI output. An example is given in this link: https://shiny.rstudio.com/reference/shiny/latest/renderUI.html
Upvotes: 0