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

Embedding from Other Documents and Tabset panels #8929

Open Huttsa opened 6 months ago

Huttsa commented 6 months ago

Bug description

I ran into this issue with a project and I tried reproducing it with just the basic Quarto manuscript project. Not sure if I have missed something in the documentation or whether this an actual bug, but decided to make a not of it.

Steps to reproduce

---
title: paneltest
authors:
  - name: Norah Jones
    affiliation: The University
    roles: writing
    corresponding: true
bibliography: references.bib
---

## Section

This is a simple placeholder for the manuscript's main document [@knuth84].

```{r}
1 + 1

{{< embed notebooks/nbsource.qmd#fig-mtcars >}}

Another embed but this time in panel

{{< embed notebooks/nbsource.qmd#fig-inpanel >}}


````qmd

---
title: "Untitled"
editor: visual
---

```{r}
#| label: fig-mtcars

library(tidyverse)

ggplot(data = mtcars, aes(x = mpg)) +
  geom_histogram() +
  labs(x = "Miles Per Gallon (mpg)", y = "Count", title = "Distribution of MPG in mtcars")

::: panel-tabset

Test

#| label: fig-inpanel

library(tidyverse)

ggplot(data = mtcars, aes(x = mpg)) +
  geom_histogram() +
  labs(x = "Miles Per Gallon (mpg)", y = "Count", title = "Distribution of MPG in mtcars")

not test

Some text :::



### Expected behavior

_No response_

### Actual behavior

Rendering HTML preview [index.qmd]
ERROR: The cell fig-inpanel does not exist in notebook

### Your environment

 R Statistical language (version 4.2.2 on Windows 10 x64 (build 22631), R studio "Ocean Storm" Release (4da58325, 2024-01-28) for windows

### Quarto check output

Quarto 1.4.549
[>] 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: 1.4.549
      Path: C:\Users\X\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: v2024.02
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Using: TinyTex
      Path: C:\Users\X\AppData\Roaming\TinyTeX\bin\windows\
      Version: 2023

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

[>] Checking Python 3 installation....OK
      Version: 3.11.2
      Path: C:/Users/X/AppData/Local/Programs/Python/Python311/python.exe
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with py -m pip install jupyter

[>] Checking R installation...........OK
      Version: 4.2.2
      Path: C:/PROGRA~1/R/R-42~1.2
      LibPaths:
        - C:/Users/X/AppData/Local/R/win-library/4.2
        - C:/Program Files/R/R-4.2.2/library
      knitr: 1.45
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK
cderv commented 6 months ago

I do thing this is similar to other issues regarding embed with .qmd. This other one is about HTML table feature for example ()

Embed for .qmd works this way:

  1. .qmd is converted to .ipynb output format
  2. embed content resolution is based on the .ipynb file
  3. .ipynb is converted for preview to a .html file

I can reproduce your issue and I see a message about Tabset panel feature not being support for output format and so default rendering will happen.

The intermediate .md will have this content

::: {#cell-fig-mtcars .cell}

```{.r .cell-code}
#| label: fig-mtcars

library(tidyverse)

::: {.cell-output .cell-output-stderr}

:::

#| label: fig-mtcars

ggplot(data = mtcars, aes(x = mpg)) +
  geom_histogram() +
  labs(x = "Miles Per Gallon (mpg)", y = "Count", title = "Distribution of MPG in mtcars")

::: {.cell-output .cell-output-stderr}

`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

:::

::: {.cell-output-display} {#fig-mtcars} ::: :::

::: panel-tabset

Test

::: {#cell-fig-inpanel .cell}

#| label: fig-inpanel

library(tidyverse)

ggplot(data = mtcars, aes(x = mpg)) +
  geom_histogram() +
  labs(x = "Miles Per Gallon (mpg)", y = "Count", title = "Distribution of MPG in mtcars")

::: {.cell-output .cell-output-stderr}

`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

:::

::: {.cell-output-display} {#fig-inpanel} ::: :::

not test

Some text :::


but when converted to .ipynb, the content is for the first part 

```json
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
<!-- truncated -->
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "`stat_bin()` using `bins = 30`. Pick better value with `binwidth`."
          ]
        },
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "image/png": 
<!-- truncated -->
          }
        }
      ],
      "source": [
        "#| label: fig-mtcars\n",
        "\n",
        "library(tidyverse)"
      ],
      "id": "cell-fig-mtcars"
    },

and for the tabset part

    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Test\n",
        "\n",
        "``` r\n",
        "#| label: fig-inpanel\n",
        "\n",
        "library(tidyverse)\n",
        "\n",
        "ggplot(data = mtcars, aes(x = mpg)) +\n",
        "  geom_histogram() +\n",
        "  labs(x = \"Miles Per Gallon (mpg)\", y = \"Count\", title = \"Distribution of MPG in mtcars\")\n",
        "```\n",
        "\n",
        "    `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.\n",
        "\n",
        "![](attachment:nbsource_files/figure-ipynb/fig-inpanel-1.png)\n",
        "\n",
        "## not test\n",
        "\n",
        "Some text"
      ],
      "attachments": {
        "nbsource_files/figure-ipynb/fig-inpanel-1.png": {
          "image/png": 
 <!-- truncated -->
        }
      },
      "id": "6d871be6-3b48-48be-966c-7dd70eda9f41"
    }
  ],

For the first we get a specific cell with the id set with fig-mtcars and this allow detection and inclusion of content.

For the second, the cell id is random and mardown content (and not display data). It contains both the content of the tabsets as markdown output, including the fig-inpanel .

So the ::: {#cell-fig-inpanel .cell} is lost and it not split. It would need to be two differents cells in the output for the embed feature to work in such case.

So currently, this means that embedding content from cell that is inside a Tabset Panels does not work.

This would need improvement in rendering to ipynb and detection of the cell.