simonw / datasette

An open source multi-tool for exploring and publishing data
https://datasette.io
Apache License 2.0
9.37k stars 668 forks source link

Possible to deploy as a python app (for Rstudio connect server)? #1217

Open plpxsk opened 3 years ago

plpxsk commented 3 years ago

Is it possible to deploy a datasette application as a python web app?

In my enterprise, I have option to deploy python apps via Rstudio Connect, and I would like to publish a datasette dashboard for sharing.

I welcome any pointers to converting datasette serve into a python app that can be run as something like python datasette.py --my_data.db

plpxsk commented 3 years ago

A good reference seems to be the note to run datasette as a module in https://github.com/simonw/datasette/pull/556

virtadpt commented 3 years ago

I've had a lot of success running it as an OpenFaaS lambda.

mattmalcher commented 1 year ago

The following worked for deployment to RStudio / Posit Connect

An app.py along the lines of:

from pathlib import Path

from datasette.app import Datasette

example_db = Path(__file__).parent / "data" / "example.db"

# use connect 'Content URL' setting here to set app to /datasette/
ds = Datasette(files=[example_db], settings={"base_url": "/datasette/"})

ds._startup_invoked = True
ds_app = ds.app()

Then to deploy, from within a virtualenv with rsconnect-python

rsconnect write-manifest fastapi -p $VIRTUAL_ENV/bin/python -e app:ds_app -o .
rsconnect deploy manifest manifest.json -n <name of connect server> -t "Example Datasette"
mattmalcher commented 1 year ago

All seems to work well, but there are some glitches to do with proxies, see #1883 .

Excited to use this :)