passing value from searchTwitter with textInput value to get_nrc_sentiment
I am planning to do a online Twitter sentiment analyzer that user can enter the search term by themselves using flexdashboard. Here is the code.
#Getting search term
textInput("data", label = "Enter search term", value = "", width = NULL, placeholder = NULL)
sliderInput("maxTweets", "Number of recent tweets to use for analysis:", min = 10, max = 1000, value = 500)
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
twt <- searchTwitter(input$data, n=input$maxTweets, lang = "en", resultType = "recent")
)
)
#print tweets searched
twt
Here is the problem. When I run the code below, an error occurred "Error in get_nrc_sentiment: Data must be a character vector.". I have tried map_chr and as.character before but I don't have the column to select.
#Get sentiment
s <- reactive(
s<- get_nrc_sentiment(twt())
)
#Print output
s
r shiny r-markdown
add a comment |
I am planning to do a online Twitter sentiment analyzer that user can enter the search term by themselves using flexdashboard. Here is the code.
#Getting search term
textInput("data", label = "Enter search term", value = "", width = NULL, placeholder = NULL)
sliderInput("maxTweets", "Number of recent tweets to use for analysis:", min = 10, max = 1000, value = 500)
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
twt <- searchTwitter(input$data, n=input$maxTweets, lang = "en", resultType = "recent")
)
)
#print tweets searched
twt
Here is the problem. When I run the code below, an error occurred "Error in get_nrc_sentiment: Data must be a character vector.". I have tried map_chr and as.character before but I don't have the column to select.
#Get sentiment
s <- reactive(
s<- get_nrc_sentiment(twt())
)
#Print output
s
r shiny r-markdown
You're passing a data.frame or list toget_nrc_sentiment
, instead of just the column oftext
. Try,twt()$text
is it's a data frame.
– JohnCoene
Nov 10 '18 at 10:40
It returns the same error when I trieds <- get_nrc_sentiment(twt()$text)
– Janegoh95
Nov 11 '18 at 4:17
ThesearchTwitter
function is from the deprecatedtwitteR
package which returned a list, there is a function of that package calledtwListToDF
which you must run to turn the results into a data.frame. however I would strongly advise using thertweet
package instead.
– JohnCoene
Nov 11 '18 at 11:39
Although I changed my code totwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=input$maxTweets, lang = "en", resultType = "recent", include_rts = FALSE) ) )
the 's <- reactive( s<- get_nrc_sentiment(twt()$text) )` still return "Error in get_nrc_sentiment: Data must be a character vector.". I think this is caused by the self input or reactive function because when I ran thesrch <- search_tweets("#rstats", n = 1000)
it works perfectly fine.
– Janegoh95
Nov 12 '18 at 13:39
add a comment |
I am planning to do a online Twitter sentiment analyzer that user can enter the search term by themselves using flexdashboard. Here is the code.
#Getting search term
textInput("data", label = "Enter search term", value = "", width = NULL, placeholder = NULL)
sliderInput("maxTweets", "Number of recent tweets to use for analysis:", min = 10, max = 1000, value = 500)
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
twt <- searchTwitter(input$data, n=input$maxTweets, lang = "en", resultType = "recent")
)
)
#print tweets searched
twt
Here is the problem. When I run the code below, an error occurred "Error in get_nrc_sentiment: Data must be a character vector.". I have tried map_chr and as.character before but I don't have the column to select.
#Get sentiment
s <- reactive(
s<- get_nrc_sentiment(twt())
)
#Print output
s
r shiny r-markdown
I am planning to do a online Twitter sentiment analyzer that user can enter the search term by themselves using flexdashboard. Here is the code.
#Getting search term
textInput("data", label = "Enter search term", value = "", width = NULL, placeholder = NULL)
sliderInput("maxTweets", "Number of recent tweets to use for analysis:", min = 10, max = 1000, value = 500)
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
twt <- searchTwitter(input$data, n=input$maxTweets, lang = "en", resultType = "recent")
)
)
#print tweets searched
twt
Here is the problem. When I run the code below, an error occurred "Error in get_nrc_sentiment: Data must be a character vector.". I have tried map_chr and as.character before but I don't have the column to select.
#Get sentiment
s <- reactive(
s<- get_nrc_sentiment(twt())
)
#Print output
s
r shiny r-markdown
r shiny r-markdown
asked Nov 10 '18 at 7:46
Janegoh95
11
11
You're passing a data.frame or list toget_nrc_sentiment
, instead of just the column oftext
. Try,twt()$text
is it's a data frame.
– JohnCoene
Nov 10 '18 at 10:40
It returns the same error when I trieds <- get_nrc_sentiment(twt()$text)
– Janegoh95
Nov 11 '18 at 4:17
ThesearchTwitter
function is from the deprecatedtwitteR
package which returned a list, there is a function of that package calledtwListToDF
which you must run to turn the results into a data.frame. however I would strongly advise using thertweet
package instead.
– JohnCoene
Nov 11 '18 at 11:39
Although I changed my code totwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=input$maxTweets, lang = "en", resultType = "recent", include_rts = FALSE) ) )
the 's <- reactive( s<- get_nrc_sentiment(twt()$text) )` still return "Error in get_nrc_sentiment: Data must be a character vector.". I think this is caused by the self input or reactive function because when I ran thesrch <- search_tweets("#rstats", n = 1000)
it works perfectly fine.
– Janegoh95
Nov 12 '18 at 13:39
add a comment |
You're passing a data.frame or list toget_nrc_sentiment
, instead of just the column oftext
. Try,twt()$text
is it's a data frame.
– JohnCoene
Nov 10 '18 at 10:40
It returns the same error when I trieds <- get_nrc_sentiment(twt()$text)
– Janegoh95
Nov 11 '18 at 4:17
ThesearchTwitter
function is from the deprecatedtwitteR
package which returned a list, there is a function of that package calledtwListToDF
which you must run to turn the results into a data.frame. however I would strongly advise using thertweet
package instead.
– JohnCoene
Nov 11 '18 at 11:39
Although I changed my code totwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=input$maxTweets, lang = "en", resultType = "recent", include_rts = FALSE) ) )
the 's <- reactive( s<- get_nrc_sentiment(twt()$text) )` still return "Error in get_nrc_sentiment: Data must be a character vector.". I think this is caused by the self input or reactive function because when I ran thesrch <- search_tweets("#rstats", n = 1000)
it works perfectly fine.
– Janegoh95
Nov 12 '18 at 13:39
You're passing a data.frame or list to
get_nrc_sentiment
, instead of just the column of text
. Try, twt()$text
is it's a data frame.– JohnCoene
Nov 10 '18 at 10:40
You're passing a data.frame or list to
get_nrc_sentiment
, instead of just the column of text
. Try, twt()$text
is it's a data frame.– JohnCoene
Nov 10 '18 at 10:40
It returns the same error when I tried
s <- get_nrc_sentiment(twt()$text)
– Janegoh95
Nov 11 '18 at 4:17
It returns the same error when I tried
s <- get_nrc_sentiment(twt()$text)
– Janegoh95
Nov 11 '18 at 4:17
The
searchTwitter
function is from the deprecated twitteR
package which returned a list, there is a function of that package called twListToDF
which you must run to turn the results into a data.frame. however I would strongly advise using the rtweet
package instead.– JohnCoene
Nov 11 '18 at 11:39
The
searchTwitter
function is from the deprecated twitteR
package which returned a list, there is a function of that package called twListToDF
which you must run to turn the results into a data.frame. however I would strongly advise using the rtweet
package instead.– JohnCoene
Nov 11 '18 at 11:39
Although I changed my code to
twt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=input$maxTweets, lang = "en", resultType = "recent", include_rts = FALSE) ) )
the 's <- reactive( s<- get_nrc_sentiment(twt()$text) )` still return "Error in get_nrc_sentiment: Data must be a character vector.". I think this is caused by the self input or reactive function because when I ran the srch <- search_tweets("#rstats", n = 1000)
it works perfectly fine.– Janegoh95
Nov 12 '18 at 13:39
Although I changed my code to
twt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=input$maxTweets, lang = "en", resultType = "recent", include_rts = FALSE) ) )
the 's <- reactive( s<- get_nrc_sentiment(twt()$text) )` still return "Error in get_nrc_sentiment: Data must be a character vector.". I think this is caused by the self input or reactive function because when I ran the srch <- search_tweets("#rstats", n = 1000)
it works perfectly fine.– Janegoh95
Nov 12 '18 at 13:39
add a comment |
2 Answers
2
active
oldest
votes
As mentioned in my comment I would strongly advise moving to rtweet, as stated on the twitteR
Github page:
This is the start of a relatively leisurely deprecation period for twitteR, in favor of using rtweet. Please start looking to switch over to that package. If you have any questions contact myself or @mkearney
The last commit on that repository was 2 years ago.
If you want to use twitteR
nonetheless.
twt <- searchTwitter(input$data, n=100, lang = "en", resultType = "recent")
twt <- twiListToDF(twt) # turn data.frame into a list
twt$text <- as.character(twt$text) # ensure it's a character vector
class(twt)
class(twt$text)
syuzhet::get_nrc_sentiment(txt$text)
You had to make sure it was 1) a vector 2) of type character
syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World")))
#> Error in syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World"))) :
Data must be a character vector.
syuzhet::get_nrc_sentiment(list("Hello", "World"))
#> Error in syuzhet::get_nrc_sentiment(list("Hello", "World")) :
Data must be a character vector.
rtweet
returns a data.frame wheretext
if of classcharacter
– JohnCoene
Nov 13 '18 at 12:59
Sorry to bother again. I have no idea why I use the rtweet intwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
thes <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."
– Janegoh95
Nov 14 '18 at 15:43
You are usingruntime: shiny
correct? doc -reactive
functions will not work otherwise.
– JohnCoene
Nov 14 '18 at 15:46
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
1
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
|
show 3 more comments
This is my answer.
```r
#Getting search term
textInput("data", label = "Enter search term", value = "")
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
return(search_tweets(input$data, n=100, lang = "en", include_rts = FALSE))
)
)
```
````r
#Get sentiment score of tweets
s <- reactive(
return(get_nrc_sentiment(twt()$text))
)
#Print sentiment score
renderTable(head(s()))
```
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237012%2fpassing-value-from-searchtwitter-with-textinput-value-to-get-nrc-sentiment%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As mentioned in my comment I would strongly advise moving to rtweet, as stated on the twitteR
Github page:
This is the start of a relatively leisurely deprecation period for twitteR, in favor of using rtweet. Please start looking to switch over to that package. If you have any questions contact myself or @mkearney
The last commit on that repository was 2 years ago.
If you want to use twitteR
nonetheless.
twt <- searchTwitter(input$data, n=100, lang = "en", resultType = "recent")
twt <- twiListToDF(twt) # turn data.frame into a list
twt$text <- as.character(twt$text) # ensure it's a character vector
class(twt)
class(twt$text)
syuzhet::get_nrc_sentiment(txt$text)
You had to make sure it was 1) a vector 2) of type character
syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World")))
#> Error in syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World"))) :
Data must be a character vector.
syuzhet::get_nrc_sentiment(list("Hello", "World"))
#> Error in syuzhet::get_nrc_sentiment(list("Hello", "World")) :
Data must be a character vector.
rtweet
returns a data.frame wheretext
if of classcharacter
– JohnCoene
Nov 13 '18 at 12:59
Sorry to bother again. I have no idea why I use the rtweet intwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
thes <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."
– Janegoh95
Nov 14 '18 at 15:43
You are usingruntime: shiny
correct? doc -reactive
functions will not work otherwise.
– JohnCoene
Nov 14 '18 at 15:46
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
1
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
|
show 3 more comments
As mentioned in my comment I would strongly advise moving to rtweet, as stated on the twitteR
Github page:
This is the start of a relatively leisurely deprecation period for twitteR, in favor of using rtweet. Please start looking to switch over to that package. If you have any questions contact myself or @mkearney
The last commit on that repository was 2 years ago.
If you want to use twitteR
nonetheless.
twt <- searchTwitter(input$data, n=100, lang = "en", resultType = "recent")
twt <- twiListToDF(twt) # turn data.frame into a list
twt$text <- as.character(twt$text) # ensure it's a character vector
class(twt)
class(twt$text)
syuzhet::get_nrc_sentiment(txt$text)
You had to make sure it was 1) a vector 2) of type character
syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World")))
#> Error in syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World"))) :
Data must be a character vector.
syuzhet::get_nrc_sentiment(list("Hello", "World"))
#> Error in syuzhet::get_nrc_sentiment(list("Hello", "World")) :
Data must be a character vector.
rtweet
returns a data.frame wheretext
if of classcharacter
– JohnCoene
Nov 13 '18 at 12:59
Sorry to bother again. I have no idea why I use the rtweet intwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
thes <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."
– Janegoh95
Nov 14 '18 at 15:43
You are usingruntime: shiny
correct? doc -reactive
functions will not work otherwise.
– JohnCoene
Nov 14 '18 at 15:46
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
1
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
|
show 3 more comments
As mentioned in my comment I would strongly advise moving to rtweet, as stated on the twitteR
Github page:
This is the start of a relatively leisurely deprecation period for twitteR, in favor of using rtweet. Please start looking to switch over to that package. If you have any questions contact myself or @mkearney
The last commit on that repository was 2 years ago.
If you want to use twitteR
nonetheless.
twt <- searchTwitter(input$data, n=100, lang = "en", resultType = "recent")
twt <- twiListToDF(twt) # turn data.frame into a list
twt$text <- as.character(twt$text) # ensure it's a character vector
class(twt)
class(twt$text)
syuzhet::get_nrc_sentiment(txt$text)
You had to make sure it was 1) a vector 2) of type character
syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World")))
#> Error in syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World"))) :
Data must be a character vector.
syuzhet::get_nrc_sentiment(list("Hello", "World"))
#> Error in syuzhet::get_nrc_sentiment(list("Hello", "World")) :
Data must be a character vector.
As mentioned in my comment I would strongly advise moving to rtweet, as stated on the twitteR
Github page:
This is the start of a relatively leisurely deprecation period for twitteR, in favor of using rtweet. Please start looking to switch over to that package. If you have any questions contact myself or @mkearney
The last commit on that repository was 2 years ago.
If you want to use twitteR
nonetheless.
twt <- searchTwitter(input$data, n=100, lang = "en", resultType = "recent")
twt <- twiListToDF(twt) # turn data.frame into a list
twt$text <- as.character(twt$text) # ensure it's a character vector
class(twt)
class(twt$text)
syuzhet::get_nrc_sentiment(txt$text)
You had to make sure it was 1) a vector 2) of type character
syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World")))
#> Error in syuzhet::get_nrc_sentiment(as.factor(c("Hello", "World"))) :
Data must be a character vector.
syuzhet::get_nrc_sentiment(list("Hello", "World"))
#> Error in syuzhet::get_nrc_sentiment(list("Hello", "World")) :
Data must be a character vector.
edited Nov 13 '18 at 23:10
answered Nov 13 '18 at 12:58
JohnCoene
890615
890615
rtweet
returns a data.frame wheretext
if of classcharacter
– JohnCoene
Nov 13 '18 at 12:59
Sorry to bother again. I have no idea why I use the rtweet intwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
thes <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."
– Janegoh95
Nov 14 '18 at 15:43
You are usingruntime: shiny
correct? doc -reactive
functions will not work otherwise.
– JohnCoene
Nov 14 '18 at 15:46
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
1
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
|
show 3 more comments
rtweet
returns a data.frame wheretext
if of classcharacter
– JohnCoene
Nov 13 '18 at 12:59
Sorry to bother again. I have no idea why I use the rtweet intwt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
thes <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."
– Janegoh95
Nov 14 '18 at 15:43
You are usingruntime: shiny
correct? doc -reactive
functions will not work otherwise.
– JohnCoene
Nov 14 '18 at 15:46
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
1
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
rtweet
returns a data.frame where text
if of class character
– JohnCoene
Nov 13 '18 at 12:59
rtweet
returns a data.frame where text
if of class character
– JohnCoene
Nov 13 '18 at 12:59
Sorry to bother again. I have no idea why I use the rtweet in
twt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
the s <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."– Janegoh95
Nov 14 '18 at 15:43
Sorry to bother again. I have no idea why I use the rtweet in
twt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=100, lang = "en", include_rts = FALSE) ) )
the s <- reactive( s<- get_nrc_sentiment(twt()) )
still shows error with "Error in get_nrc_sentiment: Data must be a character vector."– Janegoh95
Nov 14 '18 at 15:43
You are using
runtime: shiny
correct? doc - reactive
functions will not work otherwise.– JohnCoene
Nov 14 '18 at 15:46
You are using
runtime: shiny
correct? doc - reactive
functions will not work otherwise.– JohnCoene
Nov 14 '18 at 15:46
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
Yes. Is that means there is no possible to do a self input function? Because now I am creating a sentiment analysis engine with self input function.
– Janegoh95
Nov 14 '18 at 16:38
1
1
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
Alright. Thank you very much @JohnCoene
– Janegoh95
Nov 16 '18 at 16:51
|
show 3 more comments
This is my answer.
```r
#Getting search term
textInput("data", label = "Enter search term", value = "")
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
return(search_tweets(input$data, n=100, lang = "en", include_rts = FALSE))
)
)
```
````r
#Get sentiment score of tweets
s <- reactive(
return(get_nrc_sentiment(twt()$text))
)
#Print sentiment score
renderTable(head(s()))
```
add a comment |
This is my answer.
```r
#Getting search term
textInput("data", label = "Enter search term", value = "")
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
return(search_tweets(input$data, n=100, lang = "en", include_rts = FALSE))
)
)
```
````r
#Get sentiment score of tweets
s <- reactive(
return(get_nrc_sentiment(twt()$text))
)
#Print sentiment score
renderTable(head(s()))
```
add a comment |
This is my answer.
```r
#Getting search term
textInput("data", label = "Enter search term", value = "")
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
return(search_tweets(input$data, n=100, lang = "en", include_rts = FALSE))
)
)
```
````r
#Get sentiment score of tweets
s <- reactive(
return(get_nrc_sentiment(twt()$text))
)
#Print sentiment score
renderTable(head(s()))
```
This is my answer.
```r
#Getting search term
textInput("data", label = "Enter search term", value = "")
actionButton("enter", label = "Enter")
twt <- reactive(
if(input$enter!=0)
isolate(
return(search_tweets(input$data, n=100, lang = "en", include_rts = FALSE))
)
)
```
````r
#Get sentiment score of tweets
s <- reactive(
return(get_nrc_sentiment(twt()$text))
)
#Print sentiment score
renderTable(head(s()))
```
answered Nov 16 '18 at 17:07
Janegoh95
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237012%2fpassing-value-from-searchtwitter-with-textinput-value-to-get-nrc-sentiment%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You're passing a data.frame or list to
get_nrc_sentiment
, instead of just the column oftext
. Try,twt()$text
is it's a data frame.– JohnCoene
Nov 10 '18 at 10:40
It returns the same error when I tried
s <- get_nrc_sentiment(twt()$text)
– Janegoh95
Nov 11 '18 at 4:17
The
searchTwitter
function is from the deprecatedtwitteR
package which returned a list, there is a function of that package calledtwListToDF
which you must run to turn the results into a data.frame. however I would strongly advise using thertweet
package instead.– JohnCoene
Nov 11 '18 at 11:39
Although I changed my code to
twt <- reactive( if(input$enter!=0) isolate( twt <- search_tweets(input$data, n=input$maxTweets, lang = "en", resultType = "recent", include_rts = FALSE) ) )
the 's <- reactive( s<- get_nrc_sentiment(twt()$text) )` still return "Error in get_nrc_sentiment: Data must be a character vector.". I think this is caused by the self input or reactive function because when I ran thesrch <- search_tweets("#rstats", n = 1000)
it works perfectly fine.– Janegoh95
Nov 12 '18 at 13:39