quarto-ext / shinylive

Quarto extension to embed Shinylive for Python applications
https://quarto-ext.github.io/shinylive/
MIT License
144 stars 8 forks source link

app.py not built with quarto render command #38

Closed ryanyord closed 7 months ago

ryanyord commented 7 months ago

Following the example on the readme and using that sample code. I have installed everything correctly. I then go to render:

root@f496e1c13696:/data/slive2# quarto render --output-dir _build
pandoc 
  to: html
  output-file: slive2.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: Shinylive in Quarto example

Output created: _build/slive2.html

root@f496e1c13696:/data/slive2# quarto render --output-dir _build
pandoc 
  to: html
  output-file: slive2.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: Shinylive in Quarto example

Output created: _build/slive2.html

This builds all the files it should except app.py

So when I run

root@f496e1c13696:/data/slive2# shinylive export _build _site
Traceback (most recent call last):
  File "/usr/local/bin/shinylive", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/shinylive/_main.py", line 137, in export
    _export.export(
  File "/usr/local/lib/python3.8/dist-packages/shinylive/_export.py", line 28, in export
    raise ValueError(f"Directory {appdir}/ must contain a file named app.py.")
ValueError: Directory _build/ must contain a file named app.py.

I'm really not sure how to debug from here as I get no errors while rendering?

Here is my quarto check info:

root@f496e1c13696:/data/slive2# quarto check
Quarto 1.5.13
[✓] 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.5.13
      Path: /opt/quarto/bin

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

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/local/bin
      Version: 2021

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

[✓] Checking Python 3 installation....OK
      Version: 3.8.10
      Path: /usr/bin/python3
      Jupyter: 5.7.1
      Kernels: python3

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

[✓] Checking R installation...........OK
      Version: 4.3.2
      Path: /opt/R/4.3.2/lib/R
      LibPaths:
        - /opt/R/4.3.2/lib/R/library
      knitr: (None)
      rmarkdown: (None)

      The knitr package is not available in this R installation.
      Install with install.packages("knitr")
      The rmarkdown package is not available in this R installation.
      Install with install.packages("rmarkdown")

Also the file directory if this helps:

root@f496e1c13696:/data/slive2# ls -R
.:
_build  _extensions  _quarto.yml  slive2.qmd

./_build:
shinylive-sw.js  slive2.html  slive2_files

./_build/slive2_files:
libs

./_build/slive2_files/libs:
bootstrap  clipboard  quarto-contrib  quarto-html

./_build/slive2_files/libs/bootstrap:
bootstrap-icons.css  bootstrap-icons.woff  bootstrap.min.css  bootstrap.min.js

./_build/slive2_files/libs/clipboard:
clipboard.min.js

./_build/slive2_files/libs/quarto-contrib:
shinylive-0.2.6  shinylive-quarto-css

./_build/slive2_files/libs/quarto-contrib/shinylive-0.2.6:
shinylive  shinylive-sw.js

./_build/slive2_files/libs/quarto-contrib/shinylive-0.2.6/shinylive:
Editor.css  Editor.js  chunk-7GM7ARTS.js  load-shinylive-sw.js  pyodide  pyodide-worker.js  pyright  run-python-blocks.js  shinylive.css  shinylive.js  style-resets.css

./_build/slive2_files/libs/quarto-contrib/shinylive-0.2.6/shinylive/pyodide:
anyio-4.1.0-py3-none-any.whl        distutils-1.0.0.zip                    idna-3.6-py3-none-any.whl               mdurl-0.1.2-py3-none-any.whl     pyodide.asm.data  pyparsing-3.0.9-py3-none-any.whl         sniffio-1.3.0-py3-none-any.whl            uc_micro_py-1.0.2-py3-none-any.whl
appdirs-1.4.4-py2.py3-none-any.whl  exceptiongroup-1.0.4-py3-none-any.whl  linkify_it_py-2.0.2-py3-none-any.whl    micropip-0.2.0-py3-none-any.whl  pyodide.asm.js    python_multipart-0.0.6-py3-none-any.whl  ssl-1.0.0.zip                             uvicorn-0.24.0.post1-py3-none-any.whl
asgiref-3.7.2-py3-none-any.whl      h11-0.14.0-py3-none-any.whl            markdown_it_py-3.0.0-py3-none-any.whl   openssl-1.1.1n.zip               pyodide.asm.wasm  repodata.json                            starlette-0.32.0.post1-py3-none-any.whl
click-8.1.3-py3-none-any.whl        htmltools-0.5.1-py3-none-any.whl       mdit_py_plugins-0.4.0-py3-none-any.whl  packaging-21.3-py3-none-any.whl  pyodide_py.tar    shiny-0.7.1-py3-none-any.whl             typing_extensions-4.4.0-py3-none-any.whl

./_build/slive2_files/libs/quarto-contrib/shinylive-0.2.6/shinylive/pyright:
PYRIGHT_LICENSE.txt  pyright-locale-101-c121083e2a7a54d431db.worker.js  pyright-locale-244-93121a06520a592814db.worker.js  pyright-locale-753-025cc0f8d4b408b3f912.worker.js  pyright-main-9de05813f9fe07eabc93.worker.js.LICENSE.txt
PYRIGHT_README.txt   pyright-locale-131-ab4e388ba76ce41a9bbe.worker.js  pyright-locale-372-2f2f20ca0313ae5dd1d6.worker.js  pyright-locale-846-49df54db2b702b64a1c6.worker.js  pyright-main-9de05813f9fe07eabc93.worker.js.map
README.md            pyright-locale-162-52858c93d4cbe348333a.worker.js  pyright-locale-416-213af665ac61b39bb90a.worker.js  pyright-main-9de05813f9fe07eabc93.worker.js        typeshed.en.json

./_build/slive2_files/libs/quarto-contrib/shinylive-quarto-css:
shinylive-quarto.css

./_build/slive2_files/libs/quarto-html:
anchor.min.js  popper.min.js  quarto-syntax-highlighting.css  quarto.js  tippy.css  tippy.umd.min.js

./_extensions:
quarto-ext

./_extensions/quarto-ext:
shinylive

./_extensions/quarto-ext/shinylive:
README.md  _extension.yml  resources  shinylive.lua

./_extensions/quarto-ext/shinylive/resources:
css

./_extensions/quarto-ext/shinylive/resources/css:
shinylive-quarto.css

Any help would be appreciated, thank you!

wch commented 7 months ago

After you run the quarto render command, you don't need to do shinylive export. If you want to view the page in a web browser, you can just do quarto preview instead -- the page must be served via a web server, instead of as a file from disk.

The shinylive export command is meant for converting a Shiny app.py to a web page, without involving Quarto (except in one unusual situation which doesn't apply to the example from the README).

ryanyord commented 7 months ago

Hi, thanks for the quick response.

Apologies, I was actually referring to this repo's readme.

The goal is to send an analysis or dashboard to another user with scientific results they can play around with, without the need to host the server.

What I imagined is that I could send the user an html (with necessary companion files?) and they could open this in their browser and interact with the shiny elements.

Is this possible?

Or hosting this on github.io works too, is it sufficient to just use quarto preview to do this?

wch commented 7 months ago

Ah, yes, for the way the Quarto dashboard is built for particular repository, it requires running the shinylive export command. What is happening in that repository is actually quite different from what the shinylive extension in this repository does. We are planning on making the docs explain more clearly the different scenarios.

For now, users will still have to run a local web server to view the page, like this:

python3 -m http.server --directory _site --bind localhost 8008

Hosting on github.io should work fine. That's what we do for that repository. You should be able to just copy that repository and follow the instructions to deploy to github.io.

You can't use quarto preview for that kind of document -- for that repository, the quarto render step turns it into a Shiny app (which can't be served by quarto serve) and then the shinylive export turns that into a standalone web page that runs shinylive. (Again, that is different from what happens with the shinylive extension in this repository.) Again, we are planning to improve the docs to better explain these different scenarios.

ryanyord commented 7 months ago

Ahh okay I understand now and this makes sense looking at the header of the .qmd file

This clears up all my confusion, thank you!