2

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!

asosnovsky
  • 2,158
  • 3
  • 24
  • 41
  • If you are using `renderChart2`, remove the line where you set `m1$set(dom = 'graph')`. That line is needed only with `renderChart`. Let me know if that works. – Ramnath Apr 30 '14 at 02:26
  • no that did not work, same result. As in... no plot – asosnovsky Apr 30 '14 at 02:28
  • 1
    Ah okay. You are using `mPlot`, which corresponds to the library `morrisjs`. You need to use `showOutput('graph', 'morris')`. – Ramnath Apr 30 '14 at 02:39
  • That worked! Is there anywhere I can lookup what values of lib work when? Or learn the logic for it? – asosnovsky Apr 30 '14 at 02:40
  • 1
    The [README](https://github.com/ramnathv/rCharts) here has examples of most of the libraries. By convention, `showOutput` always uses all lowercase name of the library. You can also know the library generating the plot by typing `m1$lib`. – Ramnath Apr 30 '14 at 02:42
  • Posting comment as answer so that u can close the question. – Ramnath Apr 30 '14 at 02:48

2 Answers2

4

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.

Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • dr, using this example: `nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = 'multiBarChart')` I get no output, no error, whatsoever. I'm trying to do the same for **discreteBarChart** – Atieh Dec 02 '14 at 14:50
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)
  })
})
marbel
  • 7,560
  • 6
  • 49
  • 68