0

服务器.r

文本分析成 5 大人格特质(O、C、E、A、N)

在这里,我希望在用户单击“更新视图”按钮时处理文本。然后该文本将存储在“句子”变量中,然后清理语料库,加载每个人格特征的词表文件,将 etex 输入与词表匹配,总结人格分数并显示分数和特征用户得分高

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()

    })

}

用户界面

在这里,我试图从用户那里获取文本输入并在 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"),  
    )))

我不知道如何将文本传递给 server.r 以及如何让结果显示在 ui.r 请帮助

控制台结果

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  

我该如何解决?请帮忙

4

1 回答 1

0

renderUI()可用于获取 UI 输出。此链接中给出了一个示例:https ://shiny.rstudio.com/reference/shiny/latest/renderUI.html

于 2017-06-19T08:39:32.630 回答