diff --git a/setup.cfg b/setup.cfg index b39a60d3c..b708ea475 100644 --- a/setup.cfg +++ b/setup.cfg @@ -83,6 +83,7 @@ test = missingno rsconnect-python scikit-learn + folium dev = black>=23.1.0 diff --git a/shiny/api-examples/render_display/app.py b/shiny/api-examples/render_display/app.py new file mode 100644 index 000000000..7bd372616 --- /dev/null +++ b/shiny/api-examples/render_display/app.py @@ -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())}" diff --git a/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json b/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json index d615e62b2..d651eef8c 100644 --- a/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json +++ b/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json @@ -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 } -} \ No newline at end of file +} diff --git a/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt b/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt @@ -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 diff --git a/tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json b/tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json new file mode 100644 index 000000000..704a8edb9 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json @@ -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 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/app.py b/tests/playwright/deploys/apps/shiny-express-dataframe/app.py new file mode 100644 index 000000000..5902c0a78 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/app.py @@ -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 diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt b/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt new file mode 100644 index 000000000..c87d9ef1b --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/posit-dev/py-shiny +git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools +pandas diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json b/tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json new file mode 100644 index 000000000..951af7d5a --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json @@ -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 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-folium/app.py b/tests/playwright/deploys/apps/shiny-express-folium/app.py new file mode 100644 index 000000000..15dac58e2 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-folium/app.py @@ -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() diff --git a/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt b/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt new file mode 100644 index 000000000..d7dad04f9 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/posit-dev/py-shiny +git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools +folium diff --git a/tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json b/tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json new file mode 100644 index 000000000..af98f5e27 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json @@ -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 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt @@ -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 diff --git a/tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json b/tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json new file mode 100644 index 000000000..b4cc965be --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json @@ -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 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py b/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py index 9c2013b04..94e8b2a99 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py +++ b/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py @@ -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) diff --git a/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt @@ -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 diff --git a/tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json b/tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json new file mode 100644 index 000000000..23e73f9d6 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json @@ -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 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py b/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py index 0422113b8..54fd50c64 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py +++ b/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py @@ -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) diff --git a/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt @@ -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 diff --git a/tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json b/tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json new file mode 100644 index 000000000..65e7b6352 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json @@ -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 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py b/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py index fac04a612..8168abf73 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py +++ b/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py @@ -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" diff --git a/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt @@ -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 diff --git a/tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json b/tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json new file mode 100644 index 000000000..4087ebd04 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json @@ -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 + } +} diff --git a/tests/playwright/deploys/tests/test_accordion.py b/tests/playwright/deploys/tests/test_accordion.py index e127e14c1..cf4c7a689 100644 --- a/tests/playwright/deploys/tests/test_accordion.py +++ b/tests/playwright/deploys/tests/test_accordion.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_dataframe.py b/tests/playwright/deploys/tests/test_dataframe.py new file mode 100644 index 000000000..eccd8d4b1 --- /dev/null +++ b/tests/playwright/deploys/tests/test_dataframe.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_folium.py b/tests/playwright/deploys/tests/test_folium.py new file mode 100644 index 000000000..4b25565c2 --- /dev/null +++ b/tests/playwright/deploys/tests/test_folium.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_page_default.py b/tests/playwright/deploys/tests/test_page_default.py index f08731d3d..20beae0c4 100644 --- a/tests/playwright/deploys/tests/test_page_default.py +++ b/tests/playwright/deploys/tests/test_page_default.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_page_fillable.py b/tests/playwright/deploys/tests/test_page_fillable.py index 4849a954c..a87b9fa85 100644 --- a/tests/playwright/deploys/tests/test_page_fillable.py +++ b/tests/playwright/deploys/tests/test_page_fillable.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_page_fluid.py b/tests/playwright/deploys/tests/test_page_fluid.py index e108e4031..8f0cb1a96 100644 --- a/tests/playwright/deploys/tests/test_page_fluid.py +++ b/tests/playwright/deploys/tests/test_page_fluid.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_page_sidebar.py b/tests/playwright/deploys/tests/test_page_sidebar.py index c22ecb6dd..b8a967bbf 100644 --- a/tests/playwright/deploys/tests/test_page_sidebar.py +++ b/tests/playwright/deploys/tests/test_page_sidebar.py @@ -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) diff --git a/tests/playwright/deploys/tests/test_plotly_app.py b/tests/playwright/deploys/tests/test_plotly_app.py index 64df05ef9..fc242701d 100644 --- a/tests/playwright/deploys/tests/test_plotly_app.py +++ b/tests/playwright/deploys/tests/test_plotly_app.py @@ -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) diff --git a/tests/playwright/examples/test_examples.py b/tests/playwright/examples/test_examples.py index 95b8ff02a..3d54bdbba 100644 --- a/tests/playwright/examples/test_examples.py +++ b/tests/playwright/examples/test_examples.py @@ -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 diff --git a/tests/playwright/shiny/shiny-express/dataframe/app.py b/tests/playwright/shiny/shiny-express/dataframe/app.py new file mode 100644 index 000000000..5902c0a78 --- /dev/null +++ b/tests/playwright/shiny/shiny-express/dataframe/app.py @@ -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 diff --git a/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py b/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py new file mode 100644 index 000000000..05a53c4ae --- /dev/null +++ b/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py @@ -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) diff --git a/tests/playwright/shiny/shiny-express/folium/app.py b/tests/playwright/shiny/shiny-express/folium/app.py new file mode 100644 index 000000000..15dac58e2 --- /dev/null +++ b/tests/playwright/shiny/shiny-express/folium/app.py @@ -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() diff --git a/tests/playwright/shiny/shiny-express/folium/test_folium.py b/tests/playwright/shiny/shiny-express/folium/test_folium.py new file mode 100644 index 000000000..bb126e7ab --- /dev/null +++ b/tests/playwright/shiny/shiny-express/folium/test_folium.py @@ -0,0 +1,8 @@ +from conftest import ShinyAppProc +from playwright.sync_api import Page +from utils.express_utils import verify_express_folium_render + + +def test_folium_map(page: Page, local_app: ShinyAppProc) -> None: + page.goto(local_app.url) + verify_express_folium_render(page) diff --git a/tests/playwright/shiny/shiny-express/render_display/test_render_display.py b/tests/playwright/shiny/shiny-express/render_display/test_render_display.py new file mode 100644 index 000000000..d097556f4 --- /dev/null +++ b/tests/playwright/shiny/shiny-express/render_display/test_render_display.py @@ -0,0 +1,19 @@ +from conftest import ShinyAppProc, create_doc_example_fixture +from playwright.sync_api import Page, expect + +app = create_doc_example_fixture("render_display") + +EXPECT_TIMEOUT = 30 * 1000 + + +def test_render_display(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) + expect(page.get_by_text("Text outside of render display call")).to_have_count( + 1, timeout=EXPECT_TIMEOUT + ) + expect(page.get_by_text("Text inside of render display call")).to_have_count( + 1, timeout=EXPECT_TIMEOUT + ) + expect(page.get_by_text("Dynamic slider value: 50")).to_have_count( + 1, timeout=EXPECT_TIMEOUT + ) diff --git a/tests/playwright/utils/express_utils.py b/tests/playwright/utils/express_utils.py index 5c039b6b5..a40a9abbf 100644 --- a/tests/playwright/utils/express_utils.py +++ b/tests/playwright/utils/express_utils.py @@ -2,8 +2,15 @@ import typing -from controls import Accordion, Card, LayoutNavsetTab, OutputTextVerbatim, Sidebar -from playwright.sync_api import Page +from controls import ( + Accordion, + Card, + LayoutNavsetTab, + OutputDataFrame, + OutputTextVerbatim, + Sidebar, +) +from playwright.sync_api import Page, expect from shiny import ui from shiny.express import ui as xui @@ -83,3 +90,23 @@ def verify_express_page_sidebar(page: Page) -> None: output_txt = OutputTextVerbatim(page, "txt") output_txt.expect_value("50") compare_annotations(ui.sidebar, xui.sidebar) + + +def verify_express_dataframe(page: Page) -> None: + dataframe = OutputDataFrame(page, "sample_data_frame") + dataframe.expect_n_row(6) + + +def verify_express_folium_render(page: Page) -> None: + expect(page.get_by_text("Static Map")).to_have_count(1) + expect(page.get_by_text("Map inside of render display call")).to_have_count(1) + # map inside the @render.display + expect( + page.frame_locator("iframe").nth(1).get_by_role("link", name="OpenStreetMap") + ).to_have_count(1) + # map outside of the @render.display at the top level + expect( + page.frame_locator("iframe") + .nth(0) + .get_by_role("link", name="U.S. Geological Survey") + ).to_have_count(1)