Example: Histogram

The Lively Client requires Python 3.7+ to run successfully.

Using the module to send data to a charting library.

Once the lively_client module is installed you can use it to create great looking charts. Depending on the way you installed it, you may have to restart the notebook.

from lively_client import public_client
from IPython.display import IFrame

my_client = public_client.LivelyClient()
room_url = my_client.get_unique_room_url(chart_type="Histogram", my_chart_id=None, room_name=None)
IFrame(room_url, width=700, height=400)

Note: that your room name must be unique, so choose a long random unique identifier. If you do not specify a unique identifier (e.g., None), the system automatically picks one for you, once the system has picked one you can reuse it).

This should result in the following output. You are now seeing the default histogram.

Figure: Default histogram chart.

Now prepare some sample data. The sample data must adhere to the Google Charts API for data format and options. (Later we will support more chart providers as well).

my_data_histogram = {'data' :[
          ['Dinosaur', 'Length'],
          ['Acrocanthosaurus (top-spined lizard)', 12.2],
          ['Albertosaurus (Alberta lizard)', 9.1],
          ['Allosaurus (other lizard)', 12.2],
          ['Apatosaurus (deceptive lizard)', 22.9],
          ['Archaeopteryx (ancient wing)', 0.9],
          ['Argentinosaurus (Argentina lizard)', 36.6],
          ['Ornithomimus (bird mimic)', 4.6],
          ['Oviraptor (egg robber)', 1.5],
          ['Plateosaurus (flat lizard)', 7.9],          
          ['Tyrannosaurus (tyrant lizard)', 15.2],
          ['Ultrasaurus (ultra lizard)', 30.5],
          ['Velociraptor (swift robber)', 1.8]],
  'options': {"colors": ["red"]}

room_name = my_client.room_name

# To avoid other people from sending data to your chart, this must be unique.
# We use a combination of uuid4 and uuid1 to generate this string.

# Send the data over. 
ret_message, room, ret_code = my_client.send_data(my_data_histogram, chart_type="Histogram", room_name=room_name)
print(ret_message, room, ret_code)
# Check your chart again in the output cell above, it should have updated. 

The output from this cell is the return message (“Successfully sent data”), the room id used in this example (e.g., “4690fc7d-be32-489e-8e8f-c597abd06d74b03e1a88-fb50-11e9-a528-acde480011222322473d-875b-497b-8720-ead111cc247f”) and the return code (0). Notice how the chart in the previous cell’s iframe has dynamically updated to display your data set.

Figure: Your data, in the histogram.

Share the chart with anyone.

As you run your notebook, it may be valuable to dynamically present the results of your computations. You can send data to this chart (or multiple charts) and let someone else see the data visualization without having to screenshare or share your entire notebook.


Send the resulting link to anyone who you want to give access to your chart as you talk them through the data processing step by step, perhaps updating the chart with new data as you present your findings and execute code cells in Jupyter.

Further documentation on the lively_client API: https://engagelively.com/documentation/ and Examples.

Thank you.