Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: support streamlit applications in Viewer pane #3023

Closed
isabelizimm opened this issue May 6, 2024 · 1 comment
Closed

python: support streamlit applications in Viewer pane #3023

isabelizimm opened this issue May 6, 2024 · 1 comment
Assignees
Labels
area: viewer Issues related to Viewer category. enhancement New feature or request lang: python theme: app builder

Comments

@isabelizimm
Copy link
Contributor

To fully support streamlit, we want to be able to:

  • recognize streamlit Python files and have a gesture to click "Play" and run in terminal
  • automatically open application on "Play" in Viewer pane

Notes:

Running streamlit apps uses the CLI streamlit run app_name.py, powered by asyncio.run().

@isabelizimm isabelizimm added enhancement New feature or request lang: python labels May 6, 2024
@isabelizimm isabelizimm changed the title python: support streamlit applications python: support streamlit applications in Viewer pane May 6, 2024
@juliasilge juliasilge added the area: viewer Issues related to Viewer category. label May 6, 2024
@juliasilge juliasilge added this to the Release Candidate milestone May 6, 2024
@seeM seeM self-assigned this Aug 30, 2024
@seeM seeM removed their assignment Sep 3, 2024
seeM added a commit that referenced this issue Sep 23, 2024
This PR adds support for local Python application development for the
following frameworks:

* Streamlit
* Dash
* Gradio
* FastAPI
* Flask

This is facilitated by a new extension: `positron-run-app`.

Addresses #4557,
#4555, #3023, #3027, #3024.

https://github.com/user-attachments/assets/d72e5028-a8c9-4aab-b927-4413c4e74b24

### QA notes

1. Open an application developed using one of the supported frameworks.
2. Run the relevant "Python: Run X App in Terminal" command. It should
also be the default action if you click the run button in the editor
menu.
3. It should create a terminal named after the framework, and
automatically show the app in the Viewer pane once its ready.

Here are example apps for all of the supported frameworks:

#### Streamlit

```python
import streamlit as st
x = st.slider('x')
st.write(x, 'squared is', x * x)
```

#### Dash

```python
from dash import Dash, html
app = Dash()
app.layout = [html.Div(children='Hello World')]
if __name__ == '__main__':
    app.run(debug=True)
```

#### Gradio

```python
import gradio as gr
def image_classifier(inp):
    return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
demo.launch()
```

#### FastAPI

```python
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
    return {"message": "Hello World"}
```

#### Flask

```python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"
```

### Next steps: Workbench integration

To support Workbench, we'll need to update `runApplication` to detect if
we're in Workbench, and if so, find a free port and corresponding
proxied URL (possibly related to
#4274) and pass them both to
`getTerminalOptions`.
@testlabauto
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.09.0-95
OS Version          : OSX

Test scenario(s)

Verified by adding streamlit example to qa-example-content

Link(s) to TestRail test cases run or created:

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: viewer Issues related to Viewer category. enhancement New feature or request lang: python theme: app builder
Projects
None yet
Development

No branches or pull requests

4 participants