the code is give below:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import pymysql
import dash_table
import pandas as pd
test1 = dash.Dash(‘name’)
colors = {
‘background’:’#FBD8AB’,
‘text’: ‘#000000’
}
test1.layout = html.Div(style={‘backgroundColor’:‘white’},
children=[html.Div(children =
html.Img(src=’/assets/image.png’,height=‘50’,width=‘100’),
),
html.H1(children=“DNA Uploading”,
style ={‘Align’:‘center’,
#‘border’:‘1px solid’,
‘display’:‘flex’,
‘justifyContent’:‘center’}
),
html.H4(dcc.Input(
id = ‘input-box’,
placeholder=‘Enter a path…’,
style ={‘Align’:‘center’,
‘border’:‘1px solid’,
‘width’:‘40%’,
‘height’:‘30px’
},
type=‘text’,
value=’’),
style=dict(display=‘flex’, justifyContent=‘center’)),
html.Div(html.Button(‘Submit’,id=‘button’,style ={‘Align’:‘center’,‘background’: ‘orange’}),
style={‘display’:‘flex’,
‘justifyContent’:‘center’}),
html.Div(id=‘output’,children=‘Enter the value and press submit’),
html.Div(id = ‘output-table’, style = {‘display’:‘flex’,
‘justifyContent’:‘center’,})
])
@test1.callback(
Output(‘output-table’,‘children’),
[Input(‘button’,‘n_clicks’)],
[State(‘input-box’,‘value’)])
def update_output(contents, value):
mydb= pymysql.connect(
host = “172.16.8.226”,
user = “root”,
passwd="",
database = “test”
)
mycursor= mydb.cursor()
val = (value)
sql = “UPDATE dna SET Input_path =’%s’ , started_status = 1 WHERE id =1”%(val)
try:
mycursor.execute(sql)
mydb.commit()
except:
mydb.rollback()
SQL_Query = pd.read_sql_query (“SELECT file_path, before_count, after_count FROM dna_uploading_count”,mydb)
df = pd.DataFrame(SQL_Query, columns=['file_path','before_count','after_count'])
columns=[{'name':'file_path','id':'1'},
{'name':'before_count','id':'1'},
{'name':'after_count','id':'1'}]
data=df.to_dict("rows")
return html.Div([
dash_table.DataTable(
id='table',
columns = columns,
data = data
)
])
if name == “main”:
test1.run_server(debug=True, host="10.10.92.13", port = 8000)