title: Altair chart not displaying when evaluated within a function
body: <p>The following code, taken from the Altair <a href="https://altair-viz.github.io/gallery/weather_heatmap.html" rel="nofollow noreferrer">docs</a>, correctly displays in my Jupyter Lab notebook.</p>
  <pre><code>import altair as alt
  from vega_datasets import data
  
  source = data.seattle_temps.url
  
  alt.Chart(
      source,
      title=&quot;2010 Daily High Temperature (F) in Seattle, WA&quot;
  ).mark_rect().encode(
      x='date(date):O',
      y='month(date):O',
      color=alt.Color('max(temp):Q', scale=alt.Scale(scheme=&quot;inferno&quot;)),
      tooltip=[
          alt.Tooltip('monthdate(date):T', title='Date'),
          alt.Tooltip('max(temp):Q', title='Max Temp')
      ]
  ).properties(width=550)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/mQMtd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mQMtd.png" alt="enter image description here" /></a></p>
  <p>However, if I cut and paste that exact code in a function, and then call the function, the chart no longer displays.</p>
  <pre><code>import altair as alt
  from vega_datasets import data
  
  def visualize():
      source = data.seattle_temps.url
      alt.Chart(
          source,
          title=&quot;2010 Daily High Temperature (F) in Seattle, WA&quot;
      ).mark_rect().encode(
          x='date(date):O',
          y='month(date):O',
          color=alt.Color('max(temp):Q', scale=alt.Scale(scheme=&quot;inferno&quot;)),
          tooltip=[
              alt.Tooltip('monthdate(date):T', title='Date'),
              alt.Tooltip('max(temp):Q', title='Max Temp')
          ]
      ).properties(width=550)
      
  visualize()
  </code></pre>
  <p>I read through Altair's <a href="https://altair-viz.github.io/user_guide/troubleshooting.html" rel="nofollow noreferrer">display troubleshooting</a> docs, and it seems the most common fix for this specific issue is to ensure that the chart is evaluated, which it is in this case. I'm not writing <code>chart = alt.Chart(...)</code>, I'm skipping the assignment and going straight to the evaluation, which is why it worked outside of the function.</p>
  <p>Why bother with the function? The reason I want to wrap it in a function is that I have a huge dataset (100 GBs) stored in a database. When I specify a filter to the database, the result is only 600 rows, so very manageable. I want to put this in a Jupyter Lab notebook and make the filter interative for non-technical users, so I created ipython widget for specifying the filter value. When a user specifies a filter in the widget, the widget needs a callback function to trigger the read from the database and produce the visual on the fly.</p>