Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from ast import literal_eval
- from IPython.display import HTML
- from IPython.core.magic import register_cell_magic
- !pip install vega
- from vega import VegaLite
- @register_cell_magic
- def vv(line, cell=None):
- if not cell:
- cell = line # for direct call
- if type(cell)==dict:
- d = cell
- else:
- cell = re.sub(r'\{\{(\w+)+}}', var_sub, cell)
- d = literal_eval(cell)
- config_browser_state()
- if 'data' in d:
- v = VegaLite(d)
- else:
- v = VegaLite(d, df) # need a global df
- return v
- def var_sub(m):
- v = globals()[m[1]]
- if type(v) != str:
- v = repr(v)
- return v
- def config_browser_state():
- display(HTML('''
- <script src="/static/components/requirejs/require.js"></script>
- <script>
- window.outputs = [];
- requirejs.config({
- paths: {
- base: '/static/base',
- jquery: '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min',
- },
- });
- </script>
- <style>.vega-actions {display: none}</style>
- '''))
Add Comment
Please, Sign In to add comment