Iframe won't display altair chart on data with more than 1750 rows

In an added bit of testing, I changed the return line of the server code to this: return (anvil.media.from_file('/tmp/altair.html', 'text/html'), "Chart should be visible"). This lets me return a message at the same time as the chart. Then add a ‘label’ to the app and use these lines to call the server function and display both chart and message:

    # Any code you write here will run when the form opens.
    full_output = anvil.server.call('make_plot')
    chart_obj = full_output[0]
    message = full_output[1]
    self.i_frame_1.url = chart_obj.get_url(True)
    self.label_1.text = message

This will make it so that as soon as Anvil gets the chart back from the Uplink server, it will display the message letting you know the function completed successfully.

The full Uplink Server code is below. This results in the label displaying “Chart should be visible”, but having an empty iFrame.

import anvil.server
import anvil.media

import altair as alt
import numpy as np
import pandas as pd


@anvil.server.callable
def make_plot():
  # Make a nice wiggle
  x = np.arange(0.0, 100000, 1)
  df = pd.DataFrame({
    'x': x,
    'y': np.exp(-x) * np.cos(2*np.pi*x),
  })

  # Plot it in the usual Altair way
  chart = alt.Chart(df).mark_line().encode(
    x='x',
    y='y',
  )
  
  chart.save('/tmp/altair.html')

  return (anvil.media.from_file('/tmp/altair.html', 'text/html'), "Chart should be visible")

anvil.server.wait_forever()
1 Like