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

How can I load a second app in a routing example #1349

Open
sidviny opened this issue May 3, 2024 · 0 comments
Open

How can I load a second app in a routing example #1349

sidviny opened this issue May 3, 2024 · 0 comments

Comments

@sidviny
Copy link

sidviny commented May 3, 2024

Based on the examples, I have created an example that starts two Shiny apps. I also managed the application to run in its own window on my desktop using flaskwebgui, which also can do fastapi apps. That all works, but now I want to go to my page 2 using code and this I cannot find.

import getpass
from datetime import datetime

from fastapi import FastAPI
from flaskwebgui import FlaskUI
from shiny import App, reactive, render, ui

ui_one = ui.page_fluid(
    ui.output_text("clock"),
    ui.input_action_button("page_2", "Go to page2"),   # THIS IS WHERE I NEED ASSISTANCE

    title="A simple clock",
)


ui_two = ui.page_fluid(
    ui.output_text("greeting"),
    ui.input_action_button("page_1", "Go to page1"),

    title="A simple greeter",
)


def server(input, output, session):  # noqa
    @reactive.calc
    def time():
        reactive.invalidate_later(1)
        return datetime.now().strftime("%H:%M:%S on %B %d, %Y")

    @render.text
    def greeting():
        return f"Hello {getpass.getuser()}!"

    @render.text
    def clock():
        return f"It's currently {time()}."


app_one = App(ui_one, server)
app_two = App(ui_two, server)

app = FastAPI()

app.mount("/", app_one)
app.mount("/two", app_two)

FlaskUI(app=app, server="fastapi", width=800, height=600).run()

You can run this straight from the file, you do not need to use "shiny run". In PyCharm, I just select "Current file" and run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant