Guest User

Untitled

a guest
Jul 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import re
  2. from ast import literal_eval
  3. from IPython.display import HTML
  4. from IPython.core.magic import register_cell_magic
  5.  
  6. !pip install vega
  7. from vega import VegaLite
  8.  
  9. @register_cell_magic
  10. def vv(line, cell=None):
  11. if not cell:
  12. cell = line # for direct call
  13. if type(cell)==dict:
  14. d = cell
  15. else:
  16. cell = re.sub(r'\{\{(\w+)+}}', var_sub, cell)
  17. d = literal_eval(cell)
  18. config_browser_state()
  19. if 'data' in d:
  20. v = VegaLite(d)
  21. else:
  22. v = VegaLite(d, df) # need a global df
  23. return v
  24.  
  25. def var_sub(m):
  26. v = globals()[m[1]]
  27. if type(v) != str:
  28. v = repr(v)
  29. return v
  30.  
  31. def config_browser_state():
  32. display(HTML('''
  33. <script src="/static/components/requirejs/require.js"></script>
  34. <script>
  35. window.outputs = [];
  36. requirejs.config({
  37. paths: {
  38. base: '/static/base',
  39. jquery: '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min',
  40. },
  41. });
  42. </script>
  43. <style>.vega-actions {display: none}</style>
  44. '''))
Add Comment
Please, Sign In to add comment