Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97807

Plotly Dash: auto submit once last input box/entire form has been filled

$
0
0

Currently, I have set up a page to take 3 inputs and return a status (pass/fail) after a submit button is clicked. However, I’d like to make the data entering process more efficient by automatically submitting after the last box is filled. Is there a way to do this with my current set up, using dash bootstrap’s forms, or selenium?

edit: Selenium may not be a viable option here. How about Flask-WTF? I am not familiar with Flask at all but since Dash is built on top of Flask, it may be easy to integrate my code on top of a Flask app.

Code below:

external_stylesheets = ['dbc.themes.BOOTSTRAP']
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.COSMO])

app.css.append_css({
    'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css 104'
})


def update_database(star, serial, weight, andon):
    sheet.append([datetime.now(), star, serial, weight, andon])
    raw.save(r'Unit weights_test.xlsx')


def compare_tol(star, serial, weight):
    if star is not '':
        compare_group = df_main.loc[star, 'Group']
        if float(weight) > float(df_groups.loc[compare_group, 'Upper']) or \
                float(weight) < float(df_groups.loc[compare_group, 'Lower']):
            andon = 'FAIL'
        else:
            andon = 'PASS'
    else:
        andon = '...'
    update_database(star, serial, weight, andon)
    return andon


def which_entry(label, af):
    layout = html.Div([
        dcc.Input(
            id=label,
            placeholder=f' {label}...',
            type='text',
            value='',
            autoFocus=af
        )
    ], style={'padding': '5px 5px'})
    return layout


def andon_color(andon, n_blur):
    if n_blur:
        if andon == 'PASS':
            return 'success'
        elif andon == 'FAIL':
            return 'warning'
    else:
        return 'secondary'


app.layout = html.Div([
    html.Div([
        html.Img(src='http://www.image.png',
                 width='250px')
    ]),
    html.Div([
        html.Div([
           html.H3('Scan Star Number'),
        ]),
        which_entry('Star Number', True),
        html.Div([
            html.H3('Scan Serial Number')
        ]),
        which_entry('Serial Number', False),
        html.Div([
            html.H3('Enter Unit Weight')
        ]),
        which_entry('Weight', False),
    ], style={'text-align': 'center'}),
    html.Div([
            dbc.Button('Submit', id='button', color='primary')
    ], style={'text-align': 'center',
              'width': '250px'}),
    html.Div([
        dbc.Alert(id='andon', color='secondary')
    ], style={'text-align': 'center',
              'width': '250px',
              'padding': '5px 5px'})
], style={'width': '250px'})


@app.callback(
    [
     Output('andon', 'children'),
     Output('andon', 'color'),
     Output('Star Number', 'value'),
     Output('Serial Number', 'value'),
     Output('Weight', 'value')
    ],
    [
     Input('Weight', 'n_blur')
    ],
    [
     State('Star Number', 'value'),
     State('Serial Number', 'value'),
     State('Weight', 'value')
    ]
)
def output_all(n_blur, star, serial, weight):
    if not n_blur:
        raise dash.exceptions.PreventUpdate
    andon = compare_tol(star, serial, weight)
    return andon, andon_color(andon, n_blur), '', '', ''


if __name__ == '__main__':
    app.run_server(debug=True)

Viewing all articles
Browse latest Browse all 97807

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>