Problem with deploying example app with Shiny-Server (module 'app' has no attribute 'app')

I am trying to deploy an example shiny-for-python app on a linux server with shiny-server, but I keep getting the following error message:

su: ignoring --preserve-environment, it's mutually exclusive with --login
Using Python 3.11.5 at /srv/shiny-server/Test/.venv/bin/python
Traceback (most recent call last):
  File "/opt/shiny-server/python/SockJSAdapter.py", line 220, in <module>
    run()
  File "/opt/shiny-server/python/SockJSAdapter.py", line 213, in run
    app = getattr(app_module, "app")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'app' has no attribute 'app'

As the error messages refers to a module in shiny-server, I think my virtual environment should be set up correctly.

The app I'm trying to deploy consists of the following code:

from shiny.express import input, render, ui

ui.input_slider("val", "Slider label", min=0, max=100, value=50)

@render.text
def slider_val():
    return f"Slider value: {input.val()}"

Basic .html-sites are deployed without any issues.

Best
David

1 Like

I am also getting this exact error on an aarch64 machine running Ubuntu 22.04.

I put the path of a virtual environment into my /etc/shiny-server/shiny-server.conf file:

python /home/myusr/anaconda3/envs/myshinyenv/;

Would appreciate any guidance!

The same error occurs here as well, Ubuntu 22.04, also using vanilla installations and the same basic example from the Posit playground.

Have tried different formulations in shiny-server.conf:

python /venv
ENOENT: no such file or directory, stat '/venv'

python .venv
The application exited during initialization.

python /venv/bin
ENOENT: no such file or directory, stat '/venv/bin/'

python ./venv/bin
The python path '/srv/shiny-server/sample-apps/pytestmap/venv/bin' does not contain bin/python

python ./venv
The application exited during initialization

python ./venv/
The application exited during initialization.

python /venv/bin/
The python path '/srv/shiny-server/sample-apps/pytestmap/venv/bin' does not contain bin/python

python /venv/bin/python
The application exited during initialization.

The app log file states the same as for OP, except for Python version 3.10.12 and the app name.

OK, I somehow got around.
My speculation is that shiny-server isn't yet adapted to shiny express.

Most of the simplest examples on the Posit playground have been rewritten from classic python shiny to shiny express. So also the example we've all tried.

Rewriting to the classic formulation (where you need to specify app_ui, server and app solved the problem.

Posit: Please include a super-simple py-shiny-classic example on the playground :slight_smile:

For the records, the working code is:

'''
from shiny import render, App, reactive, ui

app_ui = ui.page_fluid(
ui.input_slider("n", "N", 0, 100, 20),
ui.output_text_verbatim("txt"),
)

def server(input, output, session):

    @render.text
    def txt():
            return f"n*2 is {input.n() * 2}"

app = App(app_ui, server)

'''

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.