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

匿名 (未验证) 提交于 2019-12-03 08:28:06

问题:

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!

回答1:

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.



回答2:

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)   }) }) 


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