R: rCharts and Shiny, charts won't show up when I run it

半城伤御伤魂 提交于 2019-12-04 18:42:12

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)
  })
})
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!