Is it possible to append new figure to an existing html generated by mne.report module

External Email - Use Caution

Hi Marijin,
Thanks for the suggestion it really help. +1 for the "conpy" analysis
pipeline and your paper.

As per suggestion by Marijin, the code to append existing mne report and
customise html is as below:

Regards
Rodney

Code:

import mne
from mne.datasets import sample
from mne.report import Report

data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(raw_fname, preload=True)

def first_run():
    raw1 = raw.copy().crop(0, 20)

    raw1.save(data_path + '/MEG/sample/sub-01_raw.fif', overwrite=True)

    event_id = {'Auditory/Left': 3, 'Auditory/Right': 4}

    def raw_to_evoked(raw_fname, tmin=-0.1, tmax=0.5):
        raw = mne.io.read_raw_fif(data_path + '/MEG/sample/' + raw_fname,
preload=True)
        raw.filter(0, 40.)

        events = mne.find_events(raw, stim_channel='STI 014')
        epochs = mne.Epochs(raw, events, event_id, tmin, tmax)
        fig2 = epochs.plot();

        evoked_l = epochs['Left'].average();
        fig3 = evoked_l.plot_topomap()
        fig4 = evoked_l.plot();

        return [fig2, fig3, fig4]

    rep = Report()
    figs = raw_to_evoked('sub-01_raw.fif')
    rep.add_figs_to_section(figs , captions=['Epochs', 'Topomap',
'Butterfly'])
    rep.save('my_report.h5')

def second_run():
    fig1 = raw.plot()
    html = """
    <table class="table table-hover">
       <tr>
           <th>Meas time range</th>
           <th>Sampling freq</th>
       </tr>
       <tr>
           <td> %0.2f to %0.2f </td>
           <td> %0.2f </td>
       </tr>
    </table>
    """
    with mne.open_report('my_report.h5') as rep:
        
        # Append new figure to the existing report
        rep.add_figs_to_section(fig1,captions=['raw'])
        # add custom htmls
        rep.add_htmls_to_section(html % (raw.times[0], raw.times[-1],
raw.info['sfreq']), captions='Info table')

rep.save('report_raw_to_second_run.html',overwrite=True,open_browser=False)

first_run()
second_run()