无法在 R shiny 中呈现 rcharts/nvd3 图形
Unable to render rcharts/nvd3 graph in R shiny
我正在制作一个简单的应用程序,我想在其中呈现我的情绪分析图。如果我 运行 直接通过我在 server.R 中编写的 R 代码,我可以毫无问题地查看图表。但是当我想通过 R shiny 渲染相同内容时,问题就来了。
我的代码是:
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)
我的 data.csv 看起来像下图,极性作为一列:
按照@Victorp 的建议,更改为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)
我正在制作一个简单的应用程序,我想在其中呈现我的情绪分析图。如果我 运行 直接通过我在 server.R 中编写的 R 代码,我可以毫无问题地查看图表。但是当我想通过 R shiny 渲染相同内容时,问题就来了。
我的代码是:
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)
我的 data.csv 看起来像下图,极性作为一列:
按照@Victorp 的建议,更改为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)