quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.74k stars 305 forks source link

A single bokeh plot will be wrongly identified as several subfigures. #2107

Closed y9c closed 1 year ago

y9c commented 2 years ago

Bug description

Code:

---
title: "test webpage"
format:
  html:
    code-fold: true
execute:
  cache: true
jupyter: python3
---

```{python}
#| label: fig-demo
#| fig-cap: "This is a demo figure for debug"

from bokeh.io import output_notebook
output_notebook(hide_banner=True)

from bokeh.palettes import Spectral5
from bokeh.plotting import figure, show
from bokeh.sampledata.autompg import autompg as df
from bokeh.transform import factor_cmap

df.cyl = df.cyl.astype(str)
group = df.groupby('cyl')
cyl_cmap = factor_cmap('cyl', palette=Spectral5, factors=sorted(df.cyl.unique()))
p = figure(height=350, x_range=group, title="MPG by # Cylinders", toolbar_location=None, tools="")
p.vbar(x='cyl', top='mpg_mean', width=1, source=group, line_color=cyl_cmap, fill_color=cyl_cmap)
show(p)


Output:

![image](https://user-images.githubusercontent.com/5415510/186504610-7b9a4437-45b5-461d-b2bc-570ee8a45dd0.png)

The subfigure 1b and 1c is empty and should be exist. 

### Checklist

- [x] upgraded to the [latest nightly quarto version](https://github.com/quarto-dev/quarto-cli/releases)?
- [x] [formatted your issue](https://yihui.org/issue/#please-format-your-issue-correctly) so it is easier for us to read?
- [x] included a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [x] documented the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [x] documented which operating system you're running? If on Linux, please provide the specific distribution as well.
cscheid commented 2 years ago

It looks like there are three cells being emitted by bokeh if we run the corresponding .ipynb file:

{
 "cells": [
  {
   "cell_type": "raw",
   "id": "ff951fb8",
   "metadata": {},
   "source": [
    "---\n",
    "title: test webpage\n",
    "format:\n",
    "  html:\n",
    "    code-fold: true\n",
    "keep-md: true\n",
    "keep-ipynb: true\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fig-demo",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
        "...",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "(function(root) {...",
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div class=\"bk-root\" id=\"9107e47f-bdc3-4fc2-9fc5-fc860b2b3abe\" data-root-id=\"1003\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
        "...",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1003"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#| label: fig-demo\n",
    "#| fig-cap: This is a demo figure for debug\n",
    "\n",
    "from bokeh.io import output_notebook\n",
    "output_notebook(hide_banner=True)\n",
    "\n",
    "from bokeh.palettes import Spectral5\n",
    "from bokeh.plotting import figure, show\n",
    "from bokeh.sampledata.autompg import autompg as df\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "df.cyl = df.cyl.astype(str)\n",
    "group = df.groupby('cyl')\n",
    "cyl_cmap = factor_cmap('cyl', palette=Spectral5, factors=sorted(df.cyl.unique()))\n",
    "p = figure(height=350, x_range=group, title=\"MPG by # Cylinders\", toolbar_location=None, tools=\"\")\n",
    "p.vbar(x='cyl', top='mpg_mean', width=1, source=group, line_color=cyl_cmap, fill_color=cyl_cmap)\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36ad8b05",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

I think what's happening is that bokeh or jupyter is using the "output_type": "display_data" entry in the output to denote that this is "not really" an output cell, and so we should treat these differently in our output.

y9c commented 2 years ago

Yes. The example in another issue will have the same problem when you set the figure label as fig-xxx.

https://github.com/quarto-dev/quarto-cli/issues/1867 https://jja.quarto.pub/quarto-basics/

y9c commented 2 years ago

Hi @cscheid , can I set fig-subcap: false? I try this option but it is not working.

cscheid commented 2 years ago

No, it doesn't work like that; that option is for you to provide the different subcaptions, instead of enabling or disabling it

y9c commented 2 years ago

Thank @cscheid . I found fig-subcap: true in the document (https://quarto.org/docs/authoring/cross-references.html). So I though there is a fig-subcap: false option.

cscheid commented 2 years ago

@y9c the documentation you linked says: "If you’d like subfigure captions that include only an identifier, e.g. “(a)”, and not a text caption, then specify fig-subcap: true rather than providing explicit subcaption text:"

y9c commented 2 years ago

Thank you @cscheid .

I would like to know if there is a quick solution to fix this on the user side. Or I need to wait for a patch commit for this.

y9c commented 1 year ago

Hi @cscheid,

Is there a solution to remove subfigure caption?

Thanks.

cscheid commented 1 year ago

You will see an update here when this issue is addressed.

y9c commented 8 months ago

This issue still remains after testing the last pre-release version. This is a warning message:

WARNING: jupyter-fixup: cells without output data. Will not fixup bokeh cell

cscheid commented 8 months ago

You might need to update something else on your end. This is what I see:

image
prairie-guy commented 8 months ago

I’m still getting the bug originally posted by @y9c. I tried it for two different Bokeh example figures. It did not show up in original example. It did, however, show up in a second example I used from a Bokeh tutorial.

Thanks in advance for your help. I really want to use Bokeh reliably within Quarto.

test2.txt

image
cscheid commented 8 months ago

@prairie-guy We need more information about your installation. Can you please post the output of quarto check?

prairie-guy commented 8 months ago

Wow! Thanks for quick response @cscheid. Here you go:

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.58.3: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.450
      Path: /home/cdaniels/mambaforge/envs/biop/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.13 (Conda)
      Path: /home/cdaniels/mambaforge/envs/biop/bin/python
      Jupyter: 5.4.0
      Kernels: python3, julia-1.9, ir

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.3.2
      Path: /usr/lib/R
      LibPaths:
        - /home/cdaniels/R/x86_64-pc-linux-gnu-library/4.3
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.45
      rmarkdown: 2.25

[✓] Checking Knitr engine render......OK
cscheid commented 8 months ago

1.3.450

Can you try this instead? https://github.com/quarto-dev/quarto-cli/releases/tag/v1.4.528

prairie-guy commented 8 months ago

Not fixed. Same problem. Downloaded repo and installed most current version 1.4.529 with ./configure.sh

Quarto 99.9.9
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      Path: /home/cdaniels/junk/quarto/quarto-cli/package/dist/bin

Check file:///home/cdaniels/junk/quarto/quarto-cli/src/resources/vendor/deno-land/x/puppeteer@9-0-2/mod.ts
[✓] Checking tools....................OK
      TinyTeX: v2023.12
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/cdaniels/.TinyTeX/bin/x86_64-linux
      Version: 2023

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.0 (Conda)
      Path: /home/cdaniels/mambaforge/envs/quarto/bin/python
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with conda install jupyter

[✓] Checking R installation...........OK
      Version: 4.3.2
      Path: /usr/lib/R
      LibPaths:
        - /home/cdaniels/R/x86_64-pc-linux-gnu-library/4.3
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.45
      rmarkdown: 2.25

[✓] Checking Knitr engine render......OK

Not sure why Jupyter is not installed. (Installed with both mamba and conda). It does shows up in correct env:


Selected Jupyter core packages...
IPython          : 8.18.1
ipykernel        : 6.26.0
ipywidgets       : 8.1.1
jupyter_client   : 8.6.0
jupyter_core     : 5.5.1
jupyter_server   : 2.12.1
jupyterlab       : 4.0.9
nbclient         : 0.8.0
nbconvert        : 7.13.0
nbformat         : 5.9.2
notebook         : 7.0.6
qtconsole        : 5.5.1
traitlets        : 5.14.0
image
cderv commented 8 months ago

@cscheid @prairie-guy I can reproduce this, so I moved over to a new issue for 1.4 instead of continuing in this one.

cscheid commented 8 months ago

@prairie-guy just FYI, you have a typo in embeded-resoures: true (that should embed-resources)

prairie-guy commented 8 months ago

Thanks