Esempio n. 1
0
def notebook_cell_outputs_to_html(rv, outputs, _cls):
    # check this is image cell
    logging.debug("notebook_cell_outputs_to_html {}".format(_cls))
    html = None
    img_cell = False
    for output in outputs:
        if 'data' in output.keys():
            if 'image/png' in output['data']:
                img_cell = True

    for output in outputs:
        opkeys = output.keys()
        if 'name' in opkeys:
            if 'text' in output:
                html = ''.join(output['text'])
        elif 'data' in opkeys:
            if 'image/png' in output['data']:
                imgdata = output['data']['image/png']
                html = '<img src="data:image/png;base64,%s"></img>' % imgdata
            elif 'text/html' in output['data']:
                html = ''.join(output['data']['text/html'])
            elif 'text/plain' in output['data'] and not img_cell:
                html = output['data']['text/plain']
        elif 'ename' in opkeys:
            html = ansi_escape.sub('', output['traceback'][-1])
        if html is not None:
            rv.append(div(html, _cls))
Esempio n. 2
0
def _cell_output_to_html(rv, cell):
    '''Append html output for cell and return whether continue or not'''
    _type = cell['cell_type']
    # logging.debug("_cell_output_to_html {}".format(_type))
    _cls = ''
    if _type == 'code' and 'outputs' in cell:
        code = cell['source']
        outputs = cell['outputs']
        if not _cell_output_to_html_check_nodata(rv, code, outputs):
            return False

        _cell_output_to_html_vieworctrl(rv, code, outputs)
    elif _type == 'markdown':
        src = cell['source']
        if '<!--dashboard' in src:
            _cls = ''
            if '<!--dashboard_view-->' in src:
                _cls = 'view'
            rv.append(div(markdown(src), _cls))
    return True
Esempio n. 3
0
def run_notebook_view_cell(rv, r, cell, idx):
    logging.debug('run_notebook_view_cell')
    _type = cell['cell_type']
    if _type == 'code':
        code = cell['source']
        if '#!dashboard_view' in code:
            try:
                r.run_cell(cell, idx)
            except NoDataFound:
                logging.debug("run_cell - NoDataFound")
                raise
            else:
                outs = r.nb['cells'][idx]['outputs']
                rv += outs
                return True
    elif _type == 'markdown':
        src = cell['source']
        if '<!--dashboard_view-->' in src:
            rv.append(div(markdown(src), 'view'))
            return True