Problems deploying a panel app on AWS EC2

Hello,

I am trying to deploy panel app on an AWS EC2 instance.

When I place

app.show(port=8080, address="0.0.0.0", websocket_origin=["*"], threaded=True)

at the end of my python file and run

python app.py

I can access the app in my browser (http://localhost:8080).

But when I want to serve the app with

app.servable()

at the end of the file and run

panel serve app.py --address 0.0.0.0 --port 8080 --allow-websocket-origin="*"

I get a blank page in my brower (http://localhost:8080/app).

What I am doing wrong?

Thanks,
Legout

1 Like

Hi @legout

What you describe should work. Could you

  • Create a very small code example that reproduces the issue and share it here
  • Share a screenshot of your terminal and browser that shows its not working

?

Hi Marc,

thanks for your response. While preparing a simple example, I found out, what my problem was. :slight_smile:

I have used if __name__=="__main__": at the end of the python file. Without this, I can serve my app with panel serve ....

i.e. this works:

import panel as pn
pn.extension()

app = pn.Column("#Simple Panel App")

app.servable()

and this not:

import panel as pn
pn.extension()

app = pn.Column("#Simple Panel App")

if __name__=='__main__':
    app.servable()

Thanks again,
Legout

2 Likes

I usually use:

if __name__.startswith("bokeh_"):
    app.servable()

if __name__ == "__main__":
    app.show()

This way I can serve the app though panel serve app.py but still also run the code in vscode line by line and see the output of app.show

1 Like