-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
138 lines (114 loc) · 3.74 KB
/
app.py
File metadata and controls
138 lines (114 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import pandas as pd
import plotly.graph_objs as go
import pickle
import dash_auth
app = dash.Dash()
# Keep this out of source code repository - save in a file or a database
VALID_USERNAME_PASSWORD_PAIRS = {
'flysheet': '0000'
}
auth = dash_auth.BasicAuth(
app,
VALID_USERNAME_PASSWORD_PAIRS
)
with open("data/doctm.pkl",'rb') as f:
doctm = pickle.load(f)
with open("data/df_1.pkl",'rb') as f:
top_word = pickle.load(f)
w= 5
F= []
for i in range(30):
F.append(doctm[i+1][w])
slctid =0
trace1 = go.Bar(
x = list(range(1,31)),
y=F,
name='Topic score'
)
app.layout = html.Div([
html.Div([
html.H2(children='Topic model with Dash'),
dcc.Dropdown(
id='docid',
options=[{'label': i, 'value': i} for i in doctm.index],
placeholder='Search a document id',
searchable=True,
value=1
),
dcc.Graph(id='topic_doc',figure=go.Figure(data=trace1)
# layout=go.Layout(barmode='stack')
# )
)],style={'width': '40%', 'display': 'inline-block', 'float': 'left', 'height':'100%',"textAlign":'left'}),
html.Div([dash_table.DataTable(
id='view_doc',
columns=[{'name':i, 'id':i} for i in doctm[['paper']].columns],
data=doctm[doctm.index == slctid][['paper']].to_dict('records'),
# fixed_rows={ 'headers': True, 'data': 0 },
style_table={ 'height':'500px','overflow':'scroll'},
style_cell={
'whiteSpace': 'normal',
'height': 'auto',
# 'lineHeight': '15px',
'width':'55%',
"textAlign":"left",
'font_size': '20px',
"font-family":'Microsoft JhengHei'
},
# page_current=0,
# page_size=PAGE_SIZE,
)]
, style={'width': '55%', 'display': 'inline-block', 'float': 'right', 'height':'100%',"textAlign":'left','padding-top': '50px',}),
html.Div([dash_table.DataTable(
id='topic word',
columns=[{'name':i, 'id':i} for i in top_word.columns],
data=top_word.to_dict('records'),
# fixed_rows={ 'headers': True, 'data': 0 },
style_table={ 'height':'500px','overflow':'scroll'},
style_cell={
'whiteSpace': 'normal',
'height': 'auto',
# 'lineHeight': '15px',
'width':'55%',
"textAlign":"left"
},
style_cell_conditional=[
{
'if': {
'column_id': 'index',
},
'width':'3%'
}],
# page_current=0,
# page_size=PAGE_SIZE,
)]
, style={'width': '100%', 'display': 'inline-block', 'float': 'left', 'height':'100%',"textAlign":'left','padding-top': '50px',})
])
@app.callback(
dash.dependencies.Output('topic_doc', 'figure'),
[dash.dependencies.Input('docid', 'value')]
)
def update_figure(selected_docid):
# filtered_df = doctm[doctm.index == selected_docid]
F= []
for i in range(30):
F.append(doctm[i+1][selected_docid])
trace = []
trace.append(go.Bar(
x=list(range(1,31)),
y=F,
name='Topic score'
))
return {'data':trace}
@app.callback(
dash.dependencies.Output('view_doc', 'data'),
[dash.dependencies.Input('docid', 'value')
])
def update_table(selected_docid):
data=doctm[doctm.index == selected_docid][['paper']].to_dict('records')
return data
if __name__ == '__main__':
app.run_server(debug=False)