quarto-dev / quarto-cli

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

`embed-resources` option doesn't work when rendering from non-input directory #8208

Open hellund opened 8 months ago

hellund commented 8 months ago

Bug description

In quarto render in pre-release version 1.4.528, "--to " is incompatible with "dashboard". The output becomes funky if --to dashboard is used and these warning are outputted: [WARNING] Could not fetch resource dashboard_files/libs/clipboard/clipboard.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/quarto.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/popper.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/tippy.umd.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/anchor.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/tippy.css [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/quarto-syntax-highlighting.css [WARNING] Could not fetch resource dashboard_files/libs/bootstrap/bootstrap.min.js [WARNING] Could not fetch resource dashboard_files/libs/bootstrap/bootstrap-icons.css [WARNING] Could not fetch resource dashboard_files/libs/bootstrap/bootstrap.min.css [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/quarto-dashboard.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/stickythead.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/datatables.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/pdfmake.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/vfs_fonts.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/web-components.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/components.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/datatables.min.css [WARNING] Could not fetch resource dashboard_files/figure-html/cell-5-output-1.png

Steps to reproduce

quarto render dashboard.qmd --to dashboard --execute --output index.html -M self-contained:True

Expected behavior

Hopefully the output would look the same as when "--to dashboard" is not used and format: "dashboard" is used yaml.

Actual behavior

The output is missing a lot of resources. [WARNING] Could not fetch resource dashboard_files/libs/clipboard/clipboard.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/quarto.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/popper.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/tippy.umd.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/anchor.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/tippy.css [WARNING] Could not fetch resource dashboard_files/libs/quarto-html/quarto-syntax-highlighting.css [WARNING] Could not fetch resource dashboard_files/libs/bootstrap/bootstrap.min.js [WARNING] Could not fetch resource dashboard_files/libs/bootstrap/bootstrap-icons.css [WARNING] Could not fetch resource dashboard_files/libs/bootstrap/bootstrap.min.css [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/quarto-dashboard.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/stickythead.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/datatables.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/pdfmake.min.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/vfs_fonts.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/web-components.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/components.js [WARNING] Could not fetch resource dashboard_files/libs/quarto-dashboard/datatables.min.css [WARNING] Could not fetch resource dashboard_files/figure-html/cell-5-output-1.png

Your environment

No response

Quarto check output

`Quarto 1.4.538 [✓] 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.538 Path: /home/user/opt/quarto-1.4.538/bin

[✓] Checking tools....................OK TinyTeX: (not installed) Chromium: (not installed)

[✓] Checking LaTeX....................OK Tex: (not detected)

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

[✓] Checking Python 3 installation....OK Version: 3.10.12 (Conda) Path: /home/user/miniconda3/envs/env/bin/python Jupyter: 5.3.1 Kernels: python3

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

[✓] Checking R installation...........(None)

  Unable to locate an installed version of R.
  Install R from https://cloud.r-project.org/`
dragonstyle commented 8 months ago

I am not able to reproduce this in the latest version of Quarto. With the following document:

--- 
title: "Development Indicators by Continent"
author: "Gapminder Analytics Group"
--- 

```{python}
import plotly.express as px
df = px.data.gapminder()

Row {height=60%}

#| title: GDP and Life Expectancy 
px.scatter(  
  df, x="gdpPercap", y="lifeExp", 
  animation_frame="year", animation_group="country", 
  size="pop", color="continent", hover_name="country",
  facet_col="continent", log_x=True, size_max=45, 
  range_x=[100,100000], range_y=[25,90] 
)  

Row {height=40%}

#| title: Population
px.area(
  df, x="year", y="pop", 
  color="continent", line_group="country"
)
#| title: Life Expectancy
px.line(
  df, x="year", y="lifeExp", 
  color="continent", line_group="country"
)

and the commands:

```bash
quarto render test.qmd --to dashboard --execute --output index.html -M self-contained:True && open index.html

quarto preview test.qmd --to dashboard --execute --output index.html -M self-contained:True

All appears to work correctly. Can you share the exact example that is causing this?

hellund commented 8 months ago

Sorry for a misunderstanding. The issue occurs when i run the quarto command from another directory like this: quarto render dashboards/status/dashboard.qmd --to dashboard --execute --output index.html -M self-contained:True

mcanouil commented 8 months ago

self-contained is a deprecated option, use embed-resources instead as described in the documentation. Correct value is true.

quarto render dashboards/status/dashboard.qmd --to dashboard --execute --output index.html -M embed-resources:true
dragonstyle commented 8 months ago

This isn't related to dashboards specifically but instead is actually caused by rendering a document with the embed-resources option from a directory other than the directory which contains the input file.

cscheid commented 8 months ago

This isn't related to dashboards specifically but instead is actually caused by rendering a document with the embed-resources option from a directory other than the directory which contains the input file.

Should we error in this case (in 1.5)?

dragonstyle commented 8 months ago

Either we should error or just make it work (e.g. I think since we're doing a distinct pandoc pass to ingest the resources we might be just be able to ensure the proper cwd before we run that pass). But agree this is a 1.5 issue.

dragonstyle commented 8 months ago

This is actually a result of three things together:

1) embed-resources: true

2) --output file.html

3) call quarto render from a different directory than the input directory

This results in the _files directory being left in the input directory, while the output file is in the current working directory with relative paths to the _files directory which assumes the file in located in the input directory.

The fix for this will be to overhaul our rendering to leave the output file in place, then move the file and the _files directory together.