This seems like an ongoing question. I saw this posted a few times, I tried all the different solutions people offered. But nothing works for me. My chart won't show up when I run it :(
Here is my ui.R
## ui.R
require('rCharts')
require('shiny')
require("quantmod")
require("TTR")
require("stringr")
require('lubridate')
options(RCHART_LIB = 'polycharts')
shinyUI(pageWithSidebar(
headerPanel('test'),
sidebarPanel(p('test')
),
mainPanel(
showOutput('graph',lib='polycharts')
)
))
and here is my server.R
#Dependencies
require('rCharts')
require('shiny')
require("quantmod")
require("TTR")
require("stringr")
require('lubridate')
#functions
SYM<-function (x,loc='yahoo') {
getSymbols(x,src=loc)
return(get(x))}
data.setup<-function(data,loc='yahoo',start.date=Sys.Date()-months(1),
end.date=Sys.Date()) {
getSymbols(data,src=loc)
x<-as.data.frame(window(SYM(data,loc=loc),
start=as.character(start.date),
end=as.character(end.date)))
x$dates<-row.names(x)
return(return(x))
}
## server.r
shinyServer(function(input, output) {
output$graph <- renderChart2({
a<-data.setup('AAPL')
m1 <- mPlot(x = 'dates', y = c("AAPL.High", "AAPL.Low"), type = "Line", data = a)
m1$set(dom = 'graph')
return(m1)
})
})
*My main issue is that I can't understand how does the showOutput function works. What is the lib in showOutput referring to? I can't find any guide that explains that. I am still a newbie when it comes to environments in R. A answer aimed at that is greatly appreciated!
The showOutput
line needs to use lib = "morris"
since the OP is using mPlot
. For a full list of libraries, you can see the README. Alternately, you can also get the name of the library by typing m1$lib
.
This works as mentioned in the comments. I just add it here so it's easier to find for others.
require('rCharts')
require('shiny')
require("quantmod")
require("TTR")
require("stringr")
require('lubridate')
options(RCHART_LIB = 'morris')
shinyUI(pageWithSidebar(
headerPanel('test'),
sidebarPanel(p('test')
),
mainPanel(
showOutput('graph',lib='morris')
)
))
#Dependencies
require('rCharts')
require('shiny')
require("quantmod")
require("TTR")
require("stringr")
require('lubridate')
#functions
SYM<-function (x,loc='yahoo') {
getSymbols(x,src=loc)
return(get(x))}
data.setup<-function(data,loc='yahoo',start.date=Sys.Date()-months(1),
end.date=Sys.Date()) {
getSymbols(data,src=loc)
x<-as.data.frame(window(SYM(data,loc=loc),
start=as.character(start.date),
end=as.character(end.date)))
x$dates<-row.names(x)
return(return(x))
}
## server.r
shinyServer(function(input, output) {
output$graph <- renderChart2({
a<-data.setup('AAPL')
m1 <- mPlot(x = 'dates', y = c("AAPL.High", "AAPL.Low"), type = "Line", data = a)
return(m1)
})
})
来源:https://stackoverflow.com/questions/23378491/r-rcharts-and-shiny-charts-wont-show-up-when-i-run-it