ip = get_ipython()
from IPython.display import display
def display_with_id(obj, display_id, update=False, execute_result=False):
iopub = ip.kernel.iopub_socket
session = get_ipython().kernel.session
data, md = ip.display_formatter.format(obj)
transient = {'display_id': str(display_id)}
content = {'data': data, 'metadata': md, 'transient': transient}
if execute_result:
msg_type = 'execute_result'
content['execution_count'] = ip.execution_count
else:
msg_type = 'update_display_data' if update else 'display_data'
session.send(iopub, msg_type, content, parent=ip.parent_header)