Below is my current code. I am trying to create an app that shows a line graph of human genes and the genes linked to those. However, I am new to Plotly and have been having a lot of issues. I think I have it mostly figured out, but now it tells me that the def() in my callback has invalid syntax and I can not for the life of me figure out why. I would greatly appreciate any help. Thanks!
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import plotly.io as pio
pd.options.plotting.backend = "plotly"
pio.renderers.default = "browser"
try:
app = dash.Dash(__name__)
app.layout = html.Div([
html.Label('Search Box'),
dcc.Input(id="search_gene",
type="text",
value = '',
placeholder="Type a human gene name",
debounce = True,
minLength = 0, maxLength = 50,
autoComplete='on',
size='40'),
html.Br(),
html.Div([
html.Div([
dcc.Graph(id='mygraph')])
@app.callback(
Output('mygraph', 'figure'),
[Input('search_gene', 'value')])
def update_output(search_gene):
names_df = pd.read_csv('All_Gene_Names.csv', dtype = str, names = ['Names'])
df = pd.read_csv('list_out.csv', sep = ',', dtype = str)
df.set_index('Date')
lookup_df = pd.read_csv('Gene_Names_lookup.csv', dtype = str)
link = lookup_df.set_index('Gene_Name').Linked_Names.str.split('|').to_dict()
input_types = ['number','password','email','range','search','tel','url','hidden']
fig = px.line(df, x = 'Date', y = df.columns, height = 600)
if search_gene:
search_gene = search_gene
syns = link[search_gene]
elif search_gene is None or len(search_gene) == 0:
search_gene = df.columns
fig = px.line(dff, x = 'Date', y = search_gene, height = 600)
fig.update_traces(line_color = 'darkblue')
fig.update_layout(title="Human Gene Occurances Per Month", xaxis_title="Date", yaxis_title="Count", legend_title="Legend")
fig2 = px.line(df, x = 'Date', y = syns)
fig2.update_traces(line_color = 'black')
fig.add_trace(fig2)
fig.show()
return fig
if __name__ == '__main__':
app.run_server(debug=True)
except:
pass