Giter Club home page Giter Club logo

Comments (13)

kokes avatar kokes commented on July 30, 2024 1

Well spotted, I didn't realise the text could be a plain string. I pushed a fix (e1266d) I've also noticed that this may affect code input as well (meaning that could be a simple string, not a list), so I fixed that as well (see 647a9a). Can you double check it works as expected now?

from nbviewer.js.

improbable-22 avatar improbable-22 commented on July 30, 2024

Many thanks, that was quick! The example file linked above now works perfectly.

However when I try other notebooks which contain graphs, these are not displayed. Again only the ones generated by Literate.jl, not the ones saved directly by Jupyter. The graphs are displayed when opened locally. I wonder if this is a related issue?

However I don't have any nice short examples to hand, to share. And I seem to have broken everything locally today, and it's late. I'll try to attach one... on monday.

For now I attach a .jl file test-fig.jl.txt which I believe should have this issue, once you do this:

julia> using Literate
julia> Literate.notebook("/Users/me/Desktop/test-fig.jl", "/Users/me/Desktop/")

from nbviewer.js.

improbable-22 avatar improbable-22 commented on July 30, 2024

OK here's a test file, much like the above: test-fig.ipynb.zip

But rather than not showing the plot (as happened with some other files I can't share) this one shows it three times, the first one gigantic. In pictures:

screen shot 2018-06-01 at 11 49 38 pm
screen shot 2018-06-01 at 11 49 49 pm

As before, I've no idea where the blame lies here. But the same notebook does open correctly in nteract, and show the plot correctly.

from nbviewer.js.

kokes avatar kokes commented on July 30, 2024

I only skimmed the JSON, but my guess is: there are three formats supplied: SVG, PNG and one other (as fallbacks, I guess). And instead of choosing one, I’m rendering all three.

In general, I render all outputs I get, mostly because oftentimes it’s an image and some text above it. Not sure what the specs say in this case. Will look into it on Monday.

from nbviewer.js.

kokes avatar kokes commented on July 30, 2024

Well, the first figure is no longer huge (6c353e8), but there are still three of them. I haven't looked into the specs, but I don't feel comfortable choosing only some output to be rendered - as I said above, sometimes you want multiple objects rendered.

from nbviewer.js.

improbable-22 avatar improbable-22 commented on July 30, 2024

Thanks for circling back to this. I've just made an issue on Literate.jl as linked.

from nbviewer.js.

improbable-22 avatar improbable-22 commented on July 30, 2024

Digging a little bit, maybe this is the right spec:

https://nbformat.readthedocs.io/en/latest/format_description.html#display-data

It's not entirely spelled out there whether (say) "text/plain" and "image/png" are alternatives , or additions. Is this obvious? Certainly that seems to be what Literate is producing:

  {
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "Plot{Plots.GRBackend() n=1}",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGQCAIAAAD9V4nPAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3daXwc1Zko/OdUdaulXtTaZUtqtSxblmzMYmyZs <snip!!> ",
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
...
       "</svg>\n"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "cell_type": "code",
   "source": [
    "using Plots\n",
    "plot(rand(20))"
   ],
   "metadata": {},
   "execution_count": 2
  },

The "text/plain" option is never displayed.

Opening the file in Jupyter, the graph output is not visible at all. But running it again produces this, with just one format:

{
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" 
...
       "</svg>\n"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using Plots\n",
    "plot(rand(20))"
   ]
  },

If I explicitly make a cell which outputs two graphs (in Jupyter) then it looks like this -- each gets its own explicit "data": { :

{
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" 
...
       "<circle clip-path=\"url(#clip6603)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"222.522\" cy=\"1133.97\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip6603)\" style=\"fill:#009af9; stroke:none; fill-opacity:1\" cx=\"222.522\" cy=\"1133.97\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip6603)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"448.923\" cy=\"552.32\" r=\"18\"/>\n",
...
       "</svg>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip6800\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2000\" height=\"2000\"/>\n",
       "  </clipPath>\n",
...

       "</svg>\n"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using Plots\n",
    "display(scatter(rand(10)))\n",
    "plot(rand(5))"
   ]
  },

I attach all of these files, just in case: four-files-issue-28.zip

from nbviewer.js.

kokes avatar kokes commented on July 30, 2024

You're right - this whole thing stems from my memory that images (used to, I guess) have an imaged displayed alongside a text description (usually just dimensions). That was either in v3 or I just have a foggy memory.

In any case, I tried to reproduce it by plotting a basic matplotlib and just the image is shown in Jupyter. Just like in your example above.

So I guess the task now is to select the one canonical display type (or what sort of ordering to follow here) - do you have an idea of what that might be? When I was fixing a different thing, I noticed that I'm doing that already in text/plain vs. text/html, where the former is a fallback for the latter, see https://github.com/kokes/nbviewer.js/blob/master/lib/nbv.js#L193.

from nbviewer.js.

improbable-22 avatar improbable-22 commented on July 30, 2024

I'd guess SVG should come before PNG, just so that I can zoom in, but I don't know if there's a canonical order somewhere. I'll ask in the other thread.

from nbviewer.js.

kokes avatar kokes commented on July 30, 2024

@improbable22 This looks like it, doesn't it? https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/base.py#L16

Though I'd also check that at least one of these mime types is present.

Oh and I don't think I've ever seen text/markdown in display_data - no that I wouldn't know how to handle it, I'll just have to check it out.

from nbviewer.js.

kokes avatar kokes commented on July 30, 2024

I've morphed this into a slightly more clearly defined issue where I'd like to resolve a few other issues as well, since it's not unlikely to break a few things.

from nbviewer.js.

kokes avatar kokes commented on July 30, 2024

So it's fixed now, I'm letting the other issue open as there area few unresolved subissues.

from nbviewer.js.

improbable-22 avatar improbable-22 commented on July 30, 2024

Great, many thanks for the fix. And sorry about the rambling issue, a more focused one makes sense.

from nbviewer.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.