Hi All,
I'm quite new about posit world.
I need to create a Python flask app on posit workbench.
I did it using vscode on the workbench, but when I run I can't reach it:
if name == 'main':
# When running in Posit Workbench, apply ProxyFix middleware
# See: Tell Flask it is Behind a Proxy — Flask Documentation (2.2.x)
if 'RS_SERVER_URL' in os.environ and os.environ['RS_SERVER_URL']:
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_prefix=1)
app.run()
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
Hi @lmoraldo thank you for visiting and posting your question.
As you have found running web servers on Workbench is a little different than locally. Since you cannot access local host, Workbench proxies to a different URL which should be available in the Workbench extension for VS Code (access the extension on the left side toolbar). I will drop a screenshot below to show:
Very odd, I tried the same code on my end and I see it proxying. Could you try changing the /home to / and also let me know the command you are using to run the flask app (python -m flask run, etc.)
If I use python -m flask run --debug the application starts and I can find the proxied server and able to access website!!! (but unable to debug)
If I use the launch.json config:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py",
"FLASK_DEBUG": "1"
},
"args": [
"run"
],
"jinja": true,
"justMyCode": true
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "flask",
"justMyCode": true
}
]
}
The app starts, but not able to see the proxied server and access to the website.....
So, i think it is something related to this launch.json (I did try some changes without success)
Interesting, its good to see its working without the debugger. To dig deeper into the debug issue we will need more information from you. Could you or your server admin please file a support ticket: Posit Support - Posit Documentation
Attach the diagnostics explained on that page and I can provide background to our support team to dig in further.
In case others are looking for guidance here, the Posit Workbench User Guide has some details on how Flask or other python frameworks that require a proxy to access the running web server.
Thanks, I see documentation for couple of frameworks but some are blank like streamlit. Does it mean there is no option to do the same as for Dash, FastAPI or Flask.
Update: I relooked into Workbench extension as suggested by @tnederlof and I was able to find right url for streamlit.
However, most of them are able to be safely proxied behind the scenes and picked up by the Workbench extension. Certain frameworks require additional code to be added, so those specific examples are included in the docs.