Reputation: 1993
I am making a simple application where I want to render my sentiment analysis graph. If I run the code directly through R which I have written in server.R, I can view the graph without any problem. But the problem comes when I want to render the same through R shiny.
My code is:
require(rCharts)
a =shinyUI(pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R | NVD3"),
sidebarPanel(),
mainPanel(
showOutput("myChart", "nvd3")
)
))
require(rCharts)
require(ddply)
b= shinyServer(function(input, output) {
output$myChart <- renderChart({
newData<-read.csv("data.csv")
finaldata = data.frame()
finaldata = as.data.frame(newData$Polarity)
colnames(finaldata)<- "Polarity"
finaldata$Freq<-1
finaldata = ddply(finaldata, .(Polarity), summarize, Freq = sum(Freq), Group = "Sentiment Analysis")
n1 <- nPlot(Freq ~ Group, data = finaldata, group = 'Polarity', type = 'multiBarChart')
n1
})
})
shinyApp(ui=a, server=b)
My data.csv look like below image with Polarity as a column:
Upvotes: 1
Views: 241
Reputation: 29387
Following @Victorp suggestion, do change to renderChart2
rm(list = ls())
library(rCharts)
library(shiny)
library(plyr)
Polarity <- c(rep("positive",3),"neutral",rep("positive",4),"negative",rep("positive",10),"neutral")
newData <- as.data.frame(Polarity)
a =shinyUI(pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R | NVD3"),
sidebarPanel(),
mainPanel(
showOutput("myChart", "nvd3")
)
))
b= shinyServer(function(input, output) {
output$myChart <- renderChart2({
finaldata = data.frame()
finaldata = as.data.frame(newData$Polarity)
colnames(finaldata)<- "Polarity"
finaldata$Freq<-1
finaldata = ddply(finaldata, .(Polarity), summarize, Freq = sum(Freq), Group = "Sentiment Analysis")
n1 <- nPlot(Freq ~ Group, data = finaldata, group = 'Polarity', type = 'multiBarChart')
n1
})
})
shinyApp(ui=a, server=b)
Upvotes: 1