C2DH / journal-of-digital-history-ipynb-preflight-action

This GitHub action provides a set of tools to facilitate the life of reviewers
GNU Affero General Public License v3.0
0 stars 0 forks source link

Warning if notebook with plotly doesn't include require js library #3

Closed eliselavy closed 4 months ago

eliselavy commented 5 months ago

This method can be include in the checkjavascript.py

If in requirements.txt. contains the use of plotly Ex here: https://github.com/jdh-observer/aADj3Ljjqti2/blob/main/requirements.txt

Need to be sure the


"outputs": [
    {
     "data": {
      "text/html": [
       "        <script type=\"text/javascript\">\n",
       "        window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
       "        if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
       **"        if (typeof require !== 'undefined') {\n",
       "        require.undef(\"plotly\");\n",
       "        define('plotly', function(require, exports, module) {\n",
       "            /**\n",
       "* plotly.js v2.18.0\n",**

You can take a notebook in example here: https://github.com/C2DH/jdh-notebook/blob/master/examples/plotly.ipynb

eliselavy commented 5 months ago

Notebook not working @memerchik https://raw.githubusercontent.com/jdh-observer/aADj3Ljjqti2/f4542ccc5df86a46fdb2527c474c958083800c06/articleMaine.ipynb

you can download file here: https://github.com/jdh-observer/aADj3Ljjqti2/blob/b5aa53fd6c18597eef9297eccfed7871f8f66b52/articleMaine.ipynb

eliselavy commented 5 months ago

@memerchik testing here

ok with this example:

https://github.com/C2DH/journal-of-digital-history-ipynb-preflight-action/blob/yaroslav-dev/example/plotly.ipynb

Screenshot 2024-04-04 at 11 58 35

not ok with this one:(real article)

There are more than one cell having javascript

https://github.com/C2DH/journal-of-digital-history-ipynb-preflight-action/blob/yaroslav-dev/example/articleMaine.ipynb

https://github.com/C2DH/journal-of-digital-history-ipynb-preflight-action/actions/runs/8552752770/job/23434535034#step:4:178

File "/home/runner/work/_actions/c2dh/journal-of-digital-history-ipynb-preflight-action/yaroslav-dev/preflight.py", line 173, in <module>
    fire.Fire(main)
  File "/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/runner/work/_actions/c2dh/journal-of-digital-history-ipynb-preflight-action/yaroslav-dev/preflight.py", line 157, in main
    func_as_md, func_as_output = getattr(module, func)(notebook_json_contents, preview_url)
  File "/home/runner/work/_actions/c2dh/journal-of-digital-history-ipynb-preflight-action/yaroslav-dev/checks/checkjavascript.py", line 78, in checkjavascript
    text_html_outputs = outputs["cells"][0]["outputs"][0]["data"]["text/html"]
KeyError: 'outputs'
Error: Process completed with exit code 1.
eliselavy commented 5 months ago

Exclude test plotly if R @memerchik Screenshot 2024-04-08 at 13 16 06