Skip to content

Commit

Permalink
Add rsconnect json files(shinyapps.io tests) and folium tests (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
karangattu authored Jan 4, 2024
1 parent f926cc3 commit 3e587ab
Show file tree
Hide file tree
Showing 37 changed files with 341 additions and 24 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ test =
missingno
rsconnect-python
scikit-learn
folium

dev =
black>=23.1.0
Expand Down
19 changes: 19 additions & 0 deletions shiny/api-examples/render_display/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import datetime

from shiny import render, ui
from shiny.express import input, layout

with layout.card(id="card"):
ui.input_slider("val", "slider", 0, 100, 50)
"Text outside of render display call"
ui.tags.br()
f"Rendered time: {str(datetime.datetime.now())}"

@render.display
def render_display():
"Text inside of render display call"
ui.tags.br()
"Dynamic slider value: "
input.val()
ui.tags.br()
f"Display's rendered time: {str(datetime.datetime.now())}"
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"https://rsc.radixu.com/": {
"server_url": "https://rsc.radixu.com/",
"filename": "/Users/karangathani/Documents/GitHub/py-shiny/tests/playwright/deploys/apps/plotly_app",
"app_url": "https://rsc.radixu.com/content/fc82dde5-c4ba-4748-971b-aacc09613faa/",
"app_id": "fc82dde5-c4ba-4748-971b-aacc09613faa",
"app_guid": "fc82dde5-c4ba-4748-971b-aacc09613faa",
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/example_deploy_app_a1/",
"app_id": 10800241,
"app_guid": null,
"title": "example_deploy_app_A",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/posit-dev/py-shiny.git#egg=shiny
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/shiny_express_accordion/",
"app_id": 10800240,
"app_guid": null,
"title": "shiny_express_accordion",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
24 changes: 24 additions & 0 deletions tests/playwright/deploys/apps/shiny-express-dataframe/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pandas as pd

from shiny import render
from shiny.express import ui

data = {
"A": [1, 2, 3, 4, 5, 6],
"B": ["a", "b", "c", "d", "e", "f"],
"C": [10.1, 20.2, 30.3, 40.4, 50.5, 60.6],
"D": ["apple", "banana", "cherry", "date", "elderberry", "fig"],
"E": [True, False, True, False, True, False],
"F": ["John", "Jane", "Jim", "Jessie", "Jack", "Jill"],
}

df = pd.DataFrame(data)

ui.page_opts(fillable=True)

with ui.card(id="card"):
ui.h2("Below is a sample dataframe")

@render.data_frame
def sample_data_frame(id: str = "dataframe"):
return df
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
pandas
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/shiny-express-dataframe/",
"app_id": 10800260,
"app_guid": null,
"title": "shiny-express-dataframe",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
30 changes: 30 additions & 0 deletions tests/playwright/deploys/apps/shiny-express-folium/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import folium # pyright: ignore[reportMissingTypeStubs]

from shiny import render
from shiny.express import input, ui

locations_coords = {
"San Francisco": (37.79554, -122.39348),
"Los Angeles": (34.05026, -118.25768),
"New York": (40.71222, -74.00490),
}
ui.page_opts(full_width=False)

with ui.card(id="card"):
"Static Map"
folium.Map(
location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12
)
ui.input_radio_buttons(
"location", "Location", ["San Francisco", "New York", "Los Angeles"]
)

@render.display
def folium_map():
"Map inside of render display call"
folium.Map(
location=locations_coords[input.location()],
tiles="cartodb positron",
zoom_start=12,
)
input.location()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
folium
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/shiny-express-folium/",
"app_id": 10827011,
"app_guid": null,
"title": "shiny-express-folium",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/posit-dev/py-shiny.git#egg=shiny
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/shiny_express_page_default/",
"app_id": 10800233,
"app_guid": null,
"title": "shiny_express_page_default",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from shiny import render
from shiny.express import input, ui

ui.set_page(ui.page_fillable())
ui.page_opts(fillable=True)

with ui.card(id="card"):
ui.input_slider("a", "A", 1, 100, 50)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/posit-dev/py-shiny.git#egg=shiny
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/express_page_fillable/",
"app_id": 10800242,
"app_guid": null,
"title": "express_page_fillable",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from shiny import render
from shiny.express import input, ui

ui.set_page(ui.page_fluid())
ui.page_opts(full_width=True)

with ui.card(id="card"):
ui.input_slider("a", "A", 1, 100, 50)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/posit-dev/py-shiny.git#egg=shiny
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/express_page_fluid/",
"app_id": 10800235,
"app_guid": null,
"title": "express_page_fluid",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from shiny import render
from shiny.express import input, ui

ui.set_page(ui.page_sidebar(title="PageTitle"))
ui.page_opts(title="PageTitle")

with ui.sidebar(id="sidebar", title="SidebarTitle"):
"Sidebar Content"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/posit-dev/py-shiny.git#egg=shiny
git+https://github.com/posit-dev/py-shiny
git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"https://api.shinyapps.io": {
"server_url": "https://api.shinyapps.io",
"app_url": "https://testing-apps.shinyapps.io/express_page_sidebar/",
"app_id": 10800234,
"app_guid": null,
"title": "express_page_sidebar",
"app_mode": "python-shiny",
"app_store_version": 1
}
}
2 changes: 1 addition & 1 deletion tests/playwright/deploys/tests/test_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect"])
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_express_accordion(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
Expand Down
22 changes: 22 additions & 0 deletions tests/playwright/deploys/tests/test_dataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

import pytest
from playwright.sync_api import Page
from utils.deploy_utils import deploy
from utils.express_utils import verify_express_dataframe

APP_DIR = "shiny-express-dataframe"
APP_NAME = "shiny-express-dataframe"
PAGE_TIMEOUT = 120 * 1000
EXPECT_TIMEOUT = 30 * 1000
current_dir = os.path.dirname(os.path.abspath(__file__))
app_file_path = os.path.join(os.path.dirname(current_dir), "apps", APP_DIR)


@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_express_dataframe(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
verify_express_dataframe(page)
22 changes: 22 additions & 0 deletions tests/playwright/deploys/tests/test_folium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

import pytest
from playwright.sync_api import Page
from utils.deploy_utils import deploy
from utils.express_utils import verify_express_folium_render

APP_DIR = "shiny-express-folium"
APP_NAME = "shiny-express-folium"
PAGE_TIMEOUT = 120 * 1000
EXPECT_TIMEOUT = 30 * 1000
current_dir = os.path.dirname(os.path.abspath(__file__))
app_file_path = os.path.join(os.path.dirname(current_dir), "apps", APP_DIR)


@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_folium_map(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
verify_express_folium_render(page)
2 changes: 1 addition & 1 deletion tests/playwright/deploys/tests/test_page_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect"])
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_express_page_default(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/deploys/tests/test_page_fillable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect"])
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_express_page_fillable(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/deploys/tests/test_page_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect"])
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_express_page_fluid(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/deploys/tests/test_page_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect"])
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_express_page_sidebar(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
Expand Down
3 changes: 1 addition & 2 deletions tests/playwright/deploys/tests/test_plotly_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

@pytest.mark.integrationtest
@pytest.mark.only_browser("chromium")
@pytest.mark.parametrize("location", ["connect"])
# TODO-karan: Add shinyapps.io support once it is stable
@pytest.mark.parametrize("location", ["connect", "shinyapps"])
def test_deploys(page: Page, location: str) -> None:
page_url = deploy(location, APP_NAME, app_file_path)
page.goto(page_url, timeout=PAGE_TIMEOUT)
Expand Down
2 changes: 2 additions & 0 deletions tests/playwright/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def get_apps(path: str) -> typing.List[str]:
],
}
app_allow_external_errors: typing.List[str] = [
# if shiny express app detected
"Detected Shiny Express app",
# plotnine: https://github.com/has2k1/plotnine/issues/713
# mizani: https://github.com/has2k1/mizani/issues/34
# seaborn: https://github.com/mwaskom/seaborn/issues/3457
Expand Down
24 changes: 24 additions & 0 deletions tests/playwright/shiny/shiny-express/dataframe/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pandas as pd

from shiny import render
from shiny.express import ui

data = {
"A": [1, 2, 3, 4, 5, 6],
"B": ["a", "b", "c", "d", "e", "f"],
"C": [10.1, 20.2, 30.3, 40.4, 50.5, 60.6],
"D": ["apple", "banana", "cherry", "date", "elderberry", "fig"],
"E": [True, False, True, False, True, False],
"F": ["John", "Jane", "Jim", "Jessie", "Jack", "Jill"],
}

df = pd.DataFrame(data)

ui.page_opts(fillable=True)

with ui.card(id="card"):
ui.h2("Below is a sample dataframe")

@render.data_frame
def sample_data_frame(id: str = "dataframe"):
return df
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from conftest import ShinyAppProc
from playwright.sync_api import Page
from utils.express_utils import verify_express_dataframe


def test_page_default(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)
verify_express_dataframe(page)
Loading

0 comments on commit 3e587ab

Please sign in to comment.