r - ggvis in jupyter/ipython notebook -


it possible use rmagic use r plotting in ipython notebook.

example usage

%%r  ggplot() + geom_point(data=chickweight, aes(time, weight)) 

the next evolution of ggplot2 ggvis, has support interactive graphics. naively tried run ggvis code in notebook.

code

%%r  library(ggvis)  library(dplyr)  chickweight %>% ggvis(~time, ~weight) %>% layer_points()  

error

--------------------------------------------------------------------------- rruntimeerror                             traceback (most recent call last) <ipython-input-34-d92c06ea4af8> in <module>() ----> 1 get_ipython().run_cell_magic(u'r', u'', u'# chickweight %>% head\nchickweight %>% ggvis(~time, ~weight) %>% layer_points()')  /opt/virtualenvs/test/lib/python2.7/site-packages/ipython/core/interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)    2259             magic_arg_s = self.var_expand(line, stack_depth)    2260             self.builtin_trap: -> 2261                 result = fn(magic_arg_s, cell)    2262             return result    2263   /opt/virtualenvs/test/lib/python2.7/site-packages/rpy2/ipython/rmagic.pyc in r(self, line, cell, local_ns)  /opt/virtualenvs/test/lib/python2.7/site-packages/ipython/core/magic.pyc in <lambda>(f, *a, **k)     191     # it's overkill 1 bit of state.     192     def magic_deco(arg): --> 193         call = lambda f, *a, **k: f(*a, **k)     194      195         if callable(arg):  /opt/virtualenvs/test/lib/python2.7/site-packages/rpy2/ipython/rmagic.pyc in r(self, line, cell, local_ns)     640                     old_writeconsole = ri.get_writeconsole()     641                     ri.set_writeconsole(self.write_console) --> 642                     ro.r.show(result)     643                     text_output += self.flush()     644                     ri.set_writeconsole(old_writeconsole)  /opt/virtualenvs/test/lib/python2.7/site-packages/rpy2/robjects/functions.pyc in __call__(self, *args, **kwargs)     168                 v = kwargs.pop(k)     169                 kwargs[r_k] = v --> 170         return super(signaturetranslatedfunction, self).__call__(*args, **kwargs)     171      172 pattern_link = re.compile(r'\\link\{(.+?)\}')  /opt/virtualenvs/test/lib/python2.7/site-packages/rpy2/robjects/functions.pyc in __call__(self, *args, **kwargs)      98         k, v in kwargs.items():      99             new_kwargs[k] = conversion.py2ri(v) --> 100         res = super(function, self).__call__(*new_args, **new_kwargs)     101         res = conversion.ri2ro(res)     102         return res  rruntimeerror: error in view_static(x, ...) : unused argument (uses4 = false) 

this code works fine in rstudio.

is possible run ggvis in ipython notebook (or shiny matter, think that's problem)?

long story short, you'll have either call r's print method explicitly or customize rpy2's conversion rules ipython (not shown here).

%%r  library(ggvis)  library(dplyr)  p <- chickweight %>% ggvis(~time, ~weight) %>% layer_points()  print(p) 

note figure obtained in different page ipython notebook, breaks bit idea notebooks self-contained.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -