将文本框值传递给R文件
我试图在单击按钮时将文本框中输入的字符串值传递给另一个名为test.R的R文件 传递的值ntext被输入到test.R中的另一个变量 Server.R将文本框值传递给R文件,r,shiny,R,Shiny,我试图在单击按钮时将文本框中输入的字符串值传递给另一个名为test.R的R文件 传递的值ntext被输入到test.R中的另一个变量 Server.R shinyServer(function(input, output) { ntext <- eventReactive(input$goButton, {input$text}) output$ntext <- renderText({ntext() assign('ntext',envir=.Global
shinyServer(function(input, output) {
ntext <- eventReactive(input$goButton, {input$text})
output$ntext <- renderText({ntext()
assign('ntext',envir=.GlobalEnv)
})
})
shinyUI(fluidPage(
titlePanel("Sentiment Analysis"),
sidebarLayout(
sidebarPanel(
helpText("See current opinion around the globe " ),
textInput("text", "Keyword"),
actionButton("goButton", "Go!"),
mainPanel(
mainPanel(uiOutput('tweets_txt'))
)
)
))
s<-searchTwitter(ntext(),100,lang="en")
df <- do.call("rbind", lapply(s, as.data.frame))
df$text <- sapply(df$text,function(row) iconv(row, "latin1", "ASCII", sub=""))
#tweets_txt<-sapply(df$text,function(x) x$getText())
write.table(df$text,file="C:/Users/mtech/Desktop/Twitter/EXTRACT/SentiT/output.txt")
tweets_txt<-df$text
测试.R
shinyServer(function(input, output) {
ntext <- eventReactive(input$goButton, {input$text})
output$ntext <- renderText({ntext()
assign('ntext',envir=.GlobalEnv)
})
})
shinyUI(fluidPage(
titlePanel("Sentiment Analysis"),
sidebarLayout(
sidebarPanel(
helpText("See current opinion around the globe " ),
textInput("text", "Keyword"),
actionButton("goButton", "Go!"),
mainPanel(
mainPanel(uiOutput('tweets_txt'))
)
)
))
s<-searchTwitter(ntext(),100,lang="en")
df <- do.call("rbind", lapply(s, as.data.frame))
df$text <- sapply(df$text,function(row) iconv(row, "latin1", "ASCII", sub=""))
#tweets_txt<-sapply(df$text,function(x) x$getText())
write.table(df$text,file="C:/Users/mtech/Desktop/Twitter/EXTRACT/SentiT/output.txt")
tweets_txt<-df$text
s正如前面的评论所说,这似乎是可行的
library(shiny)
source("test.R")
ui <- fluidPage(
titlePanel("Sentiment Analysis"),
sidebarLayout(
sidebarPanel(
helpText("See current opinion around the globe " ),
textInput("text", "Keyword"),
actionButton("goButton", "Go!")),
mainPanel(
verbatimTextOutput("ntext")
)
))
server <- shinyServer(function(input, output) {
ntext <- eventReactive(input$goButton, {input$text})
output$ntext <- renderText({ntext()
testfunc(ntext())
#assign('ntext',envir=.GlobalEnv)
})
})
shinyApp(ui = ui, server = server)
库(闪亮)
来源(“test.R”)
用户界面你可以在你的应用程序中找到文件test.R
,并在该文件中编写一个函数,该函数将ntext
作为输入。尝试过,但ntext本身无法在Rit中识别为一个变量,效果很好tq,但问题是来自文本框的关键字应该在这里搜索Twitter(searchterm,100,lang=“en”)我需要将文本框中的值转移到“searchTwitter”(searchterm,100,lang=“en”)中的searchterm,以代替searchterm,但我无法使用'是我试图实现的。上述代码仅作为函数工作,而不是存储文本框中的内容。要在搜索函数中传输searchterm,您可以将其作为'searchTwitter(ntext(),100,lang=“en”)'传递。我已在nchar中编辑了使用上述代码错误测试的相关代码:找不到函数“ntext”堆栈跟踪(最里面的第一个)my Test.R应在用户在文本框中输入后运行,并单击按钮,因为源(Test.R)写在服务器测试的顶部。R运行时没有任何输入,即第一次运行时tnext中没有任何内容