quarto-dev / quarto-cli

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

Support code-link option for Shiny document #9208

Open maxdrohde opened 3 months ago

maxdrohde commented 3 months ago

Bug description

When I try to use the code-link option with Shiny in Quarto, I get an uninformative error message.

Steps to reproduce

---
title: "Test"
knitr: true
format:
  html:
    code-link: true
server: shiny
---

Test

Expected behavior

No error, or an informative message stating that code-link is not compatible with Shiny.

Actual behavior

❯ quarto serve test.qmd
Loading required namespace: shiny

processing file: test.qmd
1/1
output file: test.knit.md

pandoc
  to: html
  output-file: test.html
  standalone: true
  section-divs: true
  html-math-method: mathjax
  wrap: none
  default-image-extension: png

metadata
  document-css: false
  link-citations: true
  date-format: long
  lang: en
  title: Test
  knitr: true
  server:
    type: shiny

Error: parse error: unallowed token at this point in JSON text
                                       });
                     (right here) ------^
In addition: Warning message:
In shiny_prerendered_extract_context_serialized(html_lines, "dependencies") :
  Multiple dependencies contexts found in prerendered HTML, using last.
Execution halted

Your environment

macOS 14.4.1 BuildVersion: 23E224

Quarto check output

❯ quarto check Quarto 1.4.552 [✓] 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.552 Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK Using: Installation From Path Path: /Library/TeX/texbin Version: 2023

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

[✓] Checking Python 3 installation....OK Version: 3.11.3 Path: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 Jupyter: 5.3.0 Kernels: ir, julia-1.6, julia-1.8, julia-1.9, juliapro_v1.5.0-1-1.5, julia-1.5, julia-12-threads-1.8, python3

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

[✓] Checking R installation...........OK Version: 4.3.2 Path: /Library/Frameworks/R.framework/Resources LibPaths:

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

cderv commented 3 months ago

Thanks for the report. I can reproduce this. I'll see this something to fix, or just a conflict between shiny document and code linking - which is done by downlit.

cderv commented 1 month ago

I can confirm this is an issue with downlit processing and shiny prerendered document.

Example of content before downlit processing

<!--html_preserve-->
<script type="application/shiny-prerendered" data-context="dependencies">
{"type":"list","attributes":{},"value":[]}
</script>
<!--/html_preserve-->
<!--html_preserve-->
<script type="application/shiny-prerendered" data-context="execution_dependencies">
{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["packages"]}},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["packages","version"]},"class":{"type":"character","attributes":{},"value":["data.frame"]},"row.names":{"type":"integer","attributes":{},"value":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]}},"value":[{"type":"character","attributes":{},"value":["base","cli","compiler","datasets","digest","evaluate","fastmap","graphics","grDevices","htmltools","htmlwidgets","httpuv","jsonlite","knitr","later","lifecycle","magrittr","methods","mime","promises","R6","Rcpp","rlang","rmarkdown","shiny","stats","tools","utils","xfun","xtable","yaml"]},{"type":"character","attributes":{},"value":["4.4.0","3.6.2","4.4.0","4.4.0","0.6.35","0.23","1.2.0","4.4.0","4.4.0","0.5.8.1","1.6.4","1.6.15","1.8.8","1.47","1.3.2","1.0.4","2.0.3","4.4.0","0.12","1.3.0","2.5.1","1.0.12","1.1.3","2.27","1.8.1.1","4.4.0","4.4.0","4.4.0","0.44","1.8-4","2.3.8"]}]}]}
</script>
<!--/html_preserve-->

</main>
<!-- /main column -->
<script id = "quarto-html-after-body" type="application/javascript">

Example after for the same lines

<!--html_preserve-->
<script type="application/shiny-prerendered" data-context="dependencies">
{"type":"list","attributes":{},"value":[]}
</script><!--/html_preserve--><!--html_preserve--><script type="application/shiny-prerendered" data-context="execution_dependencies">
{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["packages"]}},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["packages","version"]},"class":{"type":"character","attributes":{},"value":["data.frame"]},"row.names":{"type":"integer","attributes":{},"value":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]}},"value":[{"type":"character","attributes":{},"value":["base","cli","compiler","datasets","digest","evaluate","fastmap","graphics","grDevices","htmltools","htmlwidgets","httpuv","jsonlite","knitr","later","lifecycle","magrittr","methods","mime","promises","R6","Rcpp","rlang","rmarkdown","shiny","stats","tools","utils","xfun","xtable","yaml"]},{"type":"character","attributes":{},"value":["4.4.0","3.6.2","4.4.0","4.4.0","0.6.35","0.23","1.2.0","4.4.0","4.4.0","0.5.8.1","1.6.4","1.6.15","1.8.8","1.47","1.3.2","1.0.4","2.0.3","4.4.0","0.12","1.3.0","2.5.1","1.0.12","1.1.3","2.27","1.8.1.1","4.4.0","4.4.0","4.4.0","0.44","1.8-4","2.3.8"]}]}]}
</script><!--/html_preserve--></main><!-- /main column --><script id="quarto-html-after-body" type="application/javascript">

We see newlines are lost and this breaks rmarkdown processing.

So this is not directly to Quarto.

cderv commented 4 weeks ago

an informative message stating that code-link is not compatible with Shiny.

We've done this. And hopefully this will be fixed in the R packages at some points.