How to run a basic app and see the output?

140 Views Asked by At

I'm trying to learn the basics of Shiny for Python. When I looked at the most 'Basic App' example from the Posit website, and then created a python file in VS Code with this exact code, I was unable to see the output when I clicked run.

How do I make the output come up on my computer? I was expecting to see the same output that is available on the Posit website.

from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_slider("n", "N", 0, 100, 20),
    ui.output_text_verbatim("txt"),
)

def server(input, output, session):
    @output
    @render.text
    def txt():
        return f"n*2 is {input.n() * 2}"

app = App(app_ui, server)
2

There are 2 best solutions below

0
Bibhav On

You need app.run() at the end to start the app:

app = App(app_ui, server)
app.run()

or

shiny run --reload <path to app>/<app name>
0
Amir nazary On

You have 2 options:

1 - Add run_app(app) at the end of your file.

2 - run shiny run --reload <PYTH_TO_YOUR_FILE> in terminal.