Skip to content

Commit

Permalink
Fix text mining input session
Browse files Browse the repository at this point in the history
  • Loading branch information
pbong committed Aug 31, 2023
1 parent 96cdd0d commit 21c05d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
23 changes: 15 additions & 8 deletions callbacks/text_mining/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@ def display_input(nb_intervals_str, homepage_is_submitted, *_):

@app.callback(
Output('text-mining-query-saved-input', 'data', allow_duplicate=True),
State('text-mining-query', 'value'),
Input({'type': 'example-text-mining',
'description': ALL}, 'n_clicks'),
prevent_initial_call=True
)
def set_input_fields(query_string, *_):
if ctx.triggered_id:
if 'text-mining-query' == ctx.triggered_id:
return query_string

def set_input_fields_with_preset_input(example_text_mining_n_clicks):
if ctx.triggered_id and not all(val == 0 for val in example_text_mining_n_clicks):
return ctx.triggered_id['description']

raise PreventUpdate


@app.callback(
Output('text-mining-query-saved-input', 'data', allow_duplicate=True),
Input('text-mining-query', 'value'),
prevent_initial_call=True
)
def set_input_fields(query_string):
return query_string


@app.callback(
Output('text-mining-query', 'value'),
Expand All @@ -54,12 +60,13 @@ def get_input_homepage_session_state(query):
Output('text-mining-query-submitted-input',
'data', allow_duplicate=True),
Input('text-mining-submit', 'n_clicks'),
Input('text-mining-query', 'n_submit'),
State('homepage-is-submitted', 'data'),
State('text-mining-query', 'value'),
prevent_initial_call=True
)
def submit_text_mining_input(text_mining_submitted_n_clicks, homepage_is_submitted, text_mining_query):
if homepage_is_submitted and text_mining_submitted_n_clicks >= 1:
def submit_text_mining_input(text_mining_submitted_n_clicks, text_mining_query_n_submit, homepage_is_submitted, text_mining_query):
if homepage_is_submitted and (text_mining_submitted_n_clicks >= 1 or text_mining_query_n_submit >= 1):
is_there_error, message = is_error(text_mining_query)

if not is_there_error:
Expand Down
10 changes: 7 additions & 3 deletions pages/analysis/text_mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@
dbc.Input(
id='text-mining-query',
type='text',
value=''
value='',
debounce=True,
n_submit=0
),

html.Div([html.Span('Examples:', className='pe-3'),
html.Span('pre-harvest sprouting',
id={'type': 'example-text-mining',
'description': 'pre-harvest sprouting'},
className='sample-genomic-interval'),
className='sample-genomic-interval',
n_clicks=0),
html.Span(',', className='sample-genomic-interval'),
html.Span('anaerobic germination',
id={'type': 'example-text-mining',
'description': 'anaerobic germination'},
className='sample-genomic-interval ms-3')],
className='sample-genomic-interval ms-3',
n_clicks=0)],
className='pt-3'),
html.Br(),

Expand Down

0 comments on commit 21c05d2

Please sign in to comment.