Skip to content

Fastapi Call websocket #3021

Closed Answered by falkoschindler
Frenz86 asked this question in Q&A
May 5, 2024 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

@Frenz86 I roughly boiled it down to the following code, even though the FastAPI part isn't needed to reproduce the problem:

import uvicorn
from fastapi import FastAPI
from nicegui import ui

app = FastAPI()

async def compute_and_update_result(num1, num2):
    somma = num1 + num2
    ui.notify(f'risultato : {somma}')
    return somma

@ui.page('/')
async def home():
    num1 = ui.number(value=1)
    num2 = ui.number(value=2)
    ui.button('risultato', on_click=lambda: compute_and_update_result(num1.value, num2.value))
    result = await compute_and_update_result(num1.value, num2.value)
    ui.markdown(f"#### result = {result}")  # didn't update

ui.run_with(app, mount_path='/')

if __name__

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Frenz86
Comment options

Comment options

You must be logged in to vote
1 reply
@Frenz86
Comment options

Answer selected by Frenz86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants