<jupyter_start><jupyter_text>Extracting Vega Lite TransformationsIn this notebook, we use extract out the [transformations](https://vega.github.io/vega-lite/docs/transform.html) in the Vega Lite spec generated by Altair and push them to the server, by adding them to the SQL query with Ibis.<jupyter_code>import altair as alt
import ibis
import jupyterlab_omnisci
import ipywidgets
import IPython.display

import sys

sys.stdout = open('/dev/stdout', 'w')<jupyter_output><empty_output><jupyter_text>Carrier namesFirst we connect to the table using Ibis:<jupyter_code>conn = ibis.omniscidb.connect(
    host='metis.mapd.com', user='mapd', password='<PASSWORD>',
    port=443, database='mapd', protocol= 'https'
)

t = conn.table('flights_donotmodify')<jupyter_output><empty_output><jupyter_text>Then we compose an Altair chart using an ibis expression.<jupyter_code>c = alt.Chart(t[t.carrier_name]).mark_bar().encode(
    x='carrier_name',
    y='count()'
)<jupyter_output><empty_output><jupyter_text>Finally, we enable rendering that extracts the aggregate expressions and adds them onto the Ibis expresion:<jupyter_code>alt.data_transformers.enable('ibis')
alt.renderers.enable('ibis')

c<jupyter_output>/home/ian/anaconda3/envs/omnisci/lib/python3.7/site-packages/altair/utils/core.py:90: UserWarning: I don't know how to infer vegalite type from 'empty'.  Defaulting to nominal.
  "Defaulting to nominal.".format(typ))<jupyter_text>The only data loaded into the browser for this chart is one row for each carrier, because the counting transformation is pushed to the SQL statement.  VDOM support: grouping by monthNow let's use VDOM to facet this by month:<jupyter_code>from vdom import div, input_
from debounce import debounce

month = 1

@debounce(0.3)
def handle_change(event):
    global month
    month = int(event['value'])
    slider_handle.update(render_slider(month))
#     chart_handle.update(render_chart(month))
    jupyterlab_omnisci.get_display(render_chart, month, display_handle=chart_handle)
    
def render_slider(month):
    return input_(
        type='range',
        min=1,
        max=12,
        step=1,
        defaultValue=month,
        onChange=handle_change
    )

def render_chart(month):
    return alt.Chart(t[t.flight_dayofmonth, t.depdelay, t.flight_month][t.flight_month == month]).mark_line().encode(
        x='flight_dayofmonth:O',
        y='average(depdelay)'
    )

slider_handle = display(render_slider(month), display_id=True)
chart_handle = jupyterlab_omnisci.get_display(render_chart, month)
from vdom import div, input_
from debounce import debounce

month2 = 1

@debounce(0.3)
def handle_change2(event):
    global month2
    month2 = int(event['value'])
    slider_handle2.update(render_slider2(month2))
#     chart_handle.update(render_chart(month))
    jupyterlab_omnisci.get_display(render_chart2, month2, display_handle=chart_handle2)
    
def render_slider2(month):
    return input_(
        type='range',
        min=1,
        max=12,
        step=1,
        defaultValue=month,
        onChange=handle_change2
    )

def render_chart2(month):
    return alt.Chart(t[t.flight_dayofmonth, t.depdelay, t.flight_month][t.flight_month == month]).mark_line().encode(
        x='flight_dayofmonth:O',
        y='average(depdelay)'
    )

slider_handle2 = display(render_slider2(month2), display_id=True)
chart_handle2 = jupyterlab_omnisci.get_display(render_chart2, month2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10731848423488574, 'fraction_numerical': 0.011859994214636968, 'mean_word_length': 4.931389365351629, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '518085', 'license': 'Apache-2.0', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1166, 'n_words': 249, 'path': 'notebooks/Interactive VDOM.ipynb', 'repo_name': 'isabella232/jupyterlab-omnisci', 'size': '3463'}