nteract / hydrogen

:atom: Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.
https://nteract.gitbooks.io/hydrogen/
MIT License
3.92k stars 334 forks source link

Export to HTML #1858

Open pascalbrunner opened 4 years ago

pascalbrunner commented 4 years ago

Summary: HTML Report export of Notebook

Motivation: Sharing my Code and Markdown Comments with my Team

Alternatives: Export to Jupyter Notebook, Import Jupyter Notebook, Export Jupyter Notebook as HTML.

Question: Is there already a possibilty? I tried HTML export, but the Output of my Code is missing (and the format doesnt look nice, but that would be ok)

wadethestealth commented 4 years ago

@pascalbrunner there is currently only exporting to a .ipynb file, and this does not yet contain outputs (see #1503) also there is no export to any other format beside .ipynb however i briefly experimented in #1080 with pdf export.

pascalbrunner commented 4 years ago

I implemented a html export possibility for myself. Perhaps it also helps somebody or somebody can write a module out of it.

This way it exports the .ipynb and a .html with rendered output in Jupyters Notebook form.

I opened atom in developer mode and changed the export notebook to the following:


export default function exportNotebook() {
  // TODO: Refactor to use promises, this is a bit "nested".
  const saveNotebook = function(filename) {
    if (!filename) {
      return;
    }
    const ext = path.extname(filename) === "" ? ".ipynb" : "";
    const fname = `${filename}${ext}`;
    writeFile(fname, stringifyNotebook(store.notebook), function(err, data) {
      if (err) {
        atom.notifications.addError("Error saving file", {
          detail: err.message
        });
      } else {
        atom.notifications.addSuccess("Save successful", {
          detail: `Saved notebook as ${fname}`
        });
      }
      const execSync = require('child_process').execSync;
      const output = execSync(`jupyter nbconvert --execute --to html ${fname}`, { encoding: 'utf-8' });  
      console.log('Output was:\n', output);
    });
  };
  dialog.showSaveDialog(saveNotebook);
}
ruzihao commented 2 years ago

@pascalbrunner Did you update the exportNoteBook function in export-notebook.js? I am trying to get it work but failed. Could you elaborate a bit more? Thanks!

Italosayan commented 1 year ago

any updates?

matibilkis commented 8 months ago

hi, i wonder if there's any instruciton on how to implement @pascalbrunner code! it seems super useful :) thanks!