![](/img/trans.png)
[英]How to make ui.R and server.R to import function and data from other file and plot in ShinyApp
[英]How to call function in server.r from ui.r
文字分析可分为五大性格特征(O,C,E,A,N)
在这里,我希望文本在用户单击“更新视图”按钮时进行处理。 然后将该文本存储在“句子”变量中,然后清理语料库,为每个人格特质加载单词列表文件,将输入的单词与单词列表进行匹配,对人格得分求和并显示得分,并且特质用户得分很高
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
我该如何解决? 请帮忙
renderUI()
可用于获取UI输出。 此链接中提供了一个示例: https : //shiny.rstudio.com/reference/shiny/latest/renderUI.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.