Example: Pie Chart

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="Pie-Chart", 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 pie chart.

Figure: Default pie 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).

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="Pie-Chart", my_chart_id=None, room_name=None)
IFrame(room_url, width=700, height=400)

my_data_pie_chart = {"data":[
    ['Name','Count'],
    ['Pac-Man', 75],
    ['Tetris', 25],
    ['Snake', 400]
] ,
  "options": {
      "title": 'What This Chart Looks Like',
  "pieSliceText": 'yes',
  "slices": {
    0: {"offset": 0.1, "color": 'green'},
    1: {"offset": 0.1, "color": 'blue'},
    2: {"offset": 0.1, "color": 'yellow'}
  },  
  "pieStartAngle": 135
  }
}

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.
print(room_name)


# Send the data over. 
ret_message, room, ret_code = my_client.send_data(my_data_pie_chart, chart_type="Pie-Chart", 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: New Pie Chart with your data

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.

my_client.get_unique_room_url()

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.