Python 根据用户在仪表板(或仪表板)中的输入打印输出

Python 根据用户在仪表板(或仪表板)中的输入打印输出,python,flask,shiny,plotly-dash,Python,Flask,Shiny,Plotly Dash,我想从用户输入的文本框中获取输入x和y if x + 2*y 3*x*y > 100: print('Blurb 1') else: print('Blurb 2') 这似乎与回调等问题纠缠在一起,尽管它可能是自包含的并且非常简单。有没有一种简单的方法可以在web应用程序中实现这一点?我发现的其他资源似乎假设了一个更复杂的目标,所以我很好奇代码可以缩减多少 我不认为不定义回调就可以完成任务,但是完成工作的代码非常简短。一个可能的解决办法是: import dash imp

我想从用户输入的文本框中获取输入
x
y

if x + 2*y 3*x*y > 100:
    print('Blurb 1')
else:
    print('Blurb 2')

这似乎与回调等问题纠缠在一起,尽管它可能是自包含的并且非常简单。有没有一种简单的方法可以在web应用程序中实现这一点?我发现的其他资源似乎假设了一个更复杂的目标,所以我很好奇代码可以缩减多少

我不认为不定义回调就可以完成任务,但是完成工作的代码非常简短。一个可能的解决办法是:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash()

app.layout = html.Div([
    html.H1("Simple input example"),
    dcc.Input(
        id='input-x',
        placeholder='Insert x value',
        type='number',
        value='',
    ),
    dcc.Input(
        id='input-y',
        placeholder='Insert y value',
        type='number',
        value='',
    ),
    html.Br(),
    html.Br(),
    html.Div(id='result')
    ])


@app.callback(
    Output('result', 'children'),
    [Input('input-x', 'value'),
     Input('input-y', 'value')]
)
def update_result(x, y):
    return "The sum is: {}".format(x + y)


if __name__ == '__main__':
        app.run_server(host='0.0.0.0', debug=True, port=50800)
这就是你得到的:


每次两个输入框中的一个更改其值时,总和的值都会更新。

我认为不定义回调就无法完成任务,但完成工作的代码非常简短。一个可能的解决办法是:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash()

app.layout = html.Div([
    html.H1("Simple input example"),
    dcc.Input(
        id='input-x',
        placeholder='Insert x value',
        type='number',
        value='',
    ),
    dcc.Input(
        id='input-y',
        placeholder='Insert y value',
        type='number',
        value='',
    ),
    html.Br(),
    html.Br(),
    html.Div(id='result')
    ])


@app.callback(
    Output('result', 'children'),
    [Input('input-x', 'value'),
     Input('input-y', 'value')]
)
def update_result(x, y):
    return "The sum is: {}".format(x + y)


if __name__ == '__main__':
        app.run_server(host='0.0.0.0', debug=True, port=50800)
这就是你得到的:

每次两个输入框中的一个更改其值时,总和的值都会更新