I have a dash app with a button and I do want that button to run a different python script on click. Here is the app, How can I configure the app in that once the button is clicked, it executes another python script:
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 2 10:36:21 2020
"""
import pathlib
import dash
import pandas as pd
from dash.dependencies import Input, Output, State
import dash_html_components as html
from dashlastodash import lastodash
from dash.exceptions import PreventUpdate
import dash_table
import os
app = dash.Dash(
__name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}]
)
os.chdir("path to working dir")
# Layout of Dash App HTML
app.layout = html.Div(
children=[html.Div(
html.Button('Detect', id='button'),
html.Div(id='output-container-button',
children='Hit the button to update.')
),
],
)
@app.callback(
dash.dependencies.Output('output-container-button', 'children'),
[dash.dependencies.Input('button', 'n_clicks')])
def run_script_onClick(n_clicks):
# Don't run unless the button has been pressed...
if not n_clicks:
raise PreventUpdate
script_path = 'path to script\\lastodash.py'
# The output of a script is always done through a file dump.
# Let's just say this call dumps some data into an `output_file`
call(["python3", script_path])
# Load your output file with "some code"
output_content = lastodash
# Now return.
return output_content
# Main
if __name__ == "__main__":
app.run_server(debug=True, port=8585)
what I did is Imported the script from the directory then tried to run but it isnt working, can someone help.
The error I get
usage: [-h] [--debug] lasfile
: error: the following arguments are required: lasfile
An exception has occurred, use %tb to see the full traceback.
Note that from dashlastodash import lastodash if the directory to which I am importing the python script to rum. lastodash is the script I am running in the app button
dashlastodashthat I'm aware of andlastodashis probably misspelled. Please post a working example.lastodashobject that you import? It's not referenced in the code.