jupyter / help

:sparkles: Need some help or have some questions? Please visit our Discourse page.
https://discourse.jupyter.org
291 stars 97 forks source link

GitHub rendering hides data ... nbconvert disables scrolling ... #268

Open jonathanrobie opened 6 years ago

jonathanrobie commented 6 years ago

I am creating notebooks that I want to show people who do not need to run Jupyter - they just need to see the output. Unfortunately, if I just check these notebooks in to GitHub, the text is not displaying.

To get around this problem, I am currently using nbviewer to convert to HTML, then manually changing the stylesheet to enable scrollable windows, but that's a hassle, especially when trying to show people the current status of the notebook. Done this way, the results that look like this:

http://jonathanrobie.biblicalhumanities.org/assets/SplitConstituents.html

image

But uploading to GitHub with the data does not work, the text does not display:

https://github.com/biblicalhumanities/greek-new-testament/blob/master/labnotes/SplitConstituents.ipynb

image

The data is there, though it is not rendered. I have verified this by cloning the repo and looking at the file.

Here's the contents of a cell that is not displayed as it is stored in the notebook, showing just the first part.

     "data": {
      "text/html": [
       "<p>\n",
       "  <b>Matt.1.20</b>\n",
       "  <br/>\n",
       "  <w title=\"pron :  οὗτος plural neuter accusative\">ταῦτα</w>\n",
       "  <w title=\"conj :  δέ\">δὲ</w>\n",
       "  <w title=\"pron :  αὐτός singular masculine genitive\">αὐτοῦ</w>\n",
       "  <w title=\"verb :  ἐνθυμέομαι singular masculine genitive aorist passive participle\">ἐνθυμηθέντος</w>\n",
       "  <w title=\"verb :  ὁράω singular aorist middle imperative\">ἰδοὺ</w>\n",
       "  <w title=\"noun :  ἄγγελος singular masculine nominative\">ἄγγελος</w>\n",
       "  <w title=\"noun :  κύριος singular masculine genitive\">Κυρίου</w>\n",
       "  <w title=\"prep :  κατά\">κατ’</w>\n",
       "  <w title=\"noun :  ὄναρ singular neuter accusative\">ὄναρ</w>\n",
       "  <w title=\"verb :  φαίνω singular aorist passive indicative\">ἐφάνη</w>\n",
       "  <w title=\"pron :  αὐτός singular masculine dative\">αὐτῷ</w>\n",
       "  <w title=\"verb :  λέγω singular masculine nominative present active participle\">λέγων</w>\n",
       "  <w title=\"noun :  Ἰωσήφ singular masculine vocative\">Ἰωσὴφ</w>\n",
       "  <w title=\"noun :  υἱός singular masculine nominative\">υἱὸς</w>\n",
       "  <w title=\"noun :  Δαυίδ singular masculine genitive\">Δαυείδ,</w>\n",
       "  <w title=\"adv :  μή\">μὴ</w>\n",
       "  <w title=\"verb :  φοβέω singular aorist passive subjunctive\">φοβηθῇς</w>\n",
       "  <w title=\"verb :  παραλαμβάνω aorist active infinitive\">παραλαβεῖν</w>\n",
       "  <w title=\"noun :  Μαρία singular feminine accusative\">Μαρίαν</w>\n",
       "  <w title=\"det :  ὁ singular feminine accusative\">τὴν</w>\n",
       "  <w title=\"noun :  γυνή singular feminine accusative\">γυναῖκά</w>\n",
       "  <w title=\"pron :  σύ singular genitive\">σου,</w>\n",
       "  <w title=\"det :  ὁ singular neuter nominative\">τὸ</w>\n",
       "  <w title=\"conj :  γάρ\">γὰρ</w>\n",
       "  <w title=\"prep :  ἐν\">ἐν</w>\n",
       "  <w title=\"pron :  αὐτός singular feminine dative\">αὐτῇ</w>\n",
       "  <w title=\"verb :  γεννάω singular neuter nominative aorist passive participle\">γεννηθὲν</w>\n",
       "  <w style=\"color:red\" title=\"prep :  ἐκ\">ἐκ</w>\n",
       "  <w style=\"color:red\" title=\"noun :  πνεῦμα singular neuter genitive\">Πνεύματός</w>\n",
       "  <w title=\"verb :  εἰμί singular present active indicative\">ἐστιν</w>\n",
       "  <w style=\"color:red\" title=\"adj :  ἅγιος singular neuter genitive\">Ἁγίου·</w>\n",
       "  <w title=\"verb :  τίκτω singular future middle indicative\">τέξεται</w>\n",
       "  <w title=\"conj :  δέ\">δὲ</w>\n",
       "  <w title=\"noun :  υἱός singular masculine accusative\">υἱὸν</w>\n",
       "  <w title=\"conj :  καί\">καὶ</w>\n",
       "  <w title=\"verb :  καλέω singular future active indicative\">καλέσεις</w>\n",
       "  <w title=\"det :  ὁ singular neuter accusative\">τὸ</w>\n",
       "  <w title=\"noun :  ὄνομα singular neuter accusative\">ὄνομα</w>\n",
       "  <w title=\"pron :  αὐτός singular masculine genitive\">αὐτοῦ</w>\n",
       "  <w title=\"noun :  Ἰησοῦς singular masculine accusative\">Ἰησοῦν·</w>\n",
       "  <w title=\"pron :  αὐτός singular masculine nominative\">αὐτὸς</w>\n",
       "  <w title=\"conj :  γάρ\">γὰρ</w>\n",
       "  <w title=\"verb :  σῴζω singular future active indicative\">σώσει</w>\n",
       "  <w title=\"det :  ὁ singular masculine accusative\">τὸν</w>\n",
       "  <w title=\"noun :  λαός singular masculine accusative\">λαὸν</w>\n",
       "  <w title=\"pron :  αὐτός singular masculine genitive\">αὐτοῦ</w>\n",
       "  <w title=\"prep :  ἀπό\">ἀπὸ</w>\n",
       "  <w title=\"det :  ὁ plural feminine genitive\">τῶν</w>\n",
       "  <w title=\"noun :  ἁμαρτία plural feminine genitive\">ἁμαρτιῶν</w>\n",
       "  <w title=\"pron :  αὐτός plural masculine genitive\">αὐτῶν.</w>\n",
       "</p>\n",
takluyver commented 6 years ago

Github limits what is displayed for security reasons, and I'm guessing it's stripping out your <w></w> tags because it doesn't recognise them. Is it practical to display what you need to with standard HTML tags like <span>?

jonathanrobie commented 6 years ago

Excellent - that fixes one of the two problems, I can now see the output here:

https://github.com/biblicalhumanities/greek-new-testament/blob/master/labnotes/SplitConstituents.ipynb

Is there any way to get GitHub to enable the nice scrollable windows I see when running interactively? Without them, people have to read past long lists to see the next step, and they often want to look at only a small subset of the data the first time through.

takluyver commented 6 years ago

I think you'll have to make the scrolling boxes as part of your HTML output. I'm not a great HTML/CSS whizz, but I think that something like a fixed-height div with overflow-y: scroll in its styles should do the trick.

jonathanrobie commented 6 years ago

Hmmm, with nbviewer, I add the following:

/* This class is the outer container of all output sections. */
div.output_area {
  max-height: 600px;
  overflow: scroll;
 ...
}

But that doesn't seem to be the right selector for GitHub. I tried this:

    def highlight(self, query):
        self.show(self.xquery(highlight_query_string(query)))

    def show(self, html):
        display(HTML('<style type="text/css">{}</style>{}'.format (
                """div.output_area {
                        max-height: 600px;
                        overflow: scroll;)""",
                html
            )))

That seems to generate the right CSS, except that I obviously have the wrong selector:

      "text/html": [
       "<style type=\"text/css\">div.output_area {\n",
       "  \t\t\t\t\t\tmax-height: 600px;\n",
       "  \t\t\t\t\t\toverflow: scroll;)</style><p>\n",
       "  <b>Matt.1.20</b>\n",
       "  <br/>\n",
takluyver commented 6 years ago

It's possible that Github strips style tags as well as part of their security. You may be able to work it out using the 'inspect element' feature in the browser.

jonathanrobie commented 6 years ago

The 'inspect element' feature clearly shows what the problem is. The window I want to enable scrolling in is created first, my output is displayed within that window, so declaring CSS inside the window is too late.

screen shot 2017-12-16 at 1 14 32 pm

To make it scroll, I have to somehow change the CSS used to render the output_area divs that contain my output. If I convert it to HTML first, I can do this by modifying the CSS at the top of the file. Is there any way for me to influence the corresponding CSS used on GitHub?

takluyver commented 6 years ago

If it's stripping your style tags, I don't think so. You might be able to create another div inside the output and make that scrolling using inline styles. But I don't know exactly what Github strips and what it doesn't.