Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 KB | None | 0 0
  1. app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
  2. html.Div([
  3. html.Div([
  4. html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode()), className="nine columns")
  5. ], className="three columns"),
  6. html.Div([
  7. html.Div([
  8. html.Div([
  9. html.P("Select Month Range:"),
  10. ],
  11. className="two columns"
  12. ),
  13.  
  14. html.Div([
  15. dcc.RangeSlider(
  16. id='month_slider',
  17. # updatemode='drag',
  18. # count=1,
  19. min=1,
  20. max=maxmarks,
  21. step=1,
  22. value=[maxmarks - 1, maxmarks],
  23. marks=tags,
  24. pushable=1
  25. ),
  26.  
  27. ],
  28. className="six columns",
  29. style={})
  30. ],
  31. className="twelve columns",
  32. style={
  33. 'backgroundColor': '#EFEAEA',
  34. 'padding-top': '1.5em',
  35. 'padding-bottom': '1em'
  36. }),
  37. html.Div([
  38. html.Div([
  39. dcc.Dropdown(
  40. id='demographics',
  41. options=[
  42. {'label': 'All 18-49', 'value': '18-49'},
  43. {'label': 'Female 25-54', 'value': '25-54F'},
  44. {'label': 'All 25-54', 'value': '25-54'},
  45. ],
  46. placeholder="Select Demographics",
  47. )
  48. ],
  49. className="two columns",
  50. style={}),
  51. html.Div([
  52. dcc.Dropdown(
  53. id='ID',
  54. options=[
  55. {'label': '200', 'value': 200, 'type': 'number'},
  56. {'label': '250', 'value': 250, 'type': 'number'},
  57. {'label': '300', 'value': 300, 'type': 'number'},
  58. {'label': '350', 'value': 350, 'type': 'number'},
  59. {'label': '400', 'value': 400, 'type': 'number'},
  60. ],
  61. placeholder="Select ID",
  62. )
  63. ],
  64. className="two columns",
  65. style={}),
  66. html.Div([
  67. dcc.Dropdown(
  68. id='Income',
  69. options=[
  70. {'label': '50,000', 'value': 50000, 'type': 'number'},
  71. {'label': '100,000', 'value': 100000, 'type': 'number'},
  72. {'label': '200,000', 'value': 200000, 'type': 'number'},
  73. {'label': '350,000', 'value': 350000, 'type': 'number'},
  74. {'label': '500,000', 'value': 500000, 'type': 'number'},
  75. ],
  76. placeholder="Select Income",
  77. )
  78. ],
  79. className="two columns",
  80. style={}),
  81. html.Div([
  82. dcc.Dropdown(
  83. id='Frquency',
  84. options=[
  85. {'label': 'None per week, 'value': 0, 'type': 'number'},
  86. {'label': 'Once per Week', 'value': 1, 'type': 'number'},
  87. {'label': 'Thrice per Week', 'value': 3, 'type': 'number'},
  88. ],
  89. placeholder="Select Frequency",
  90. )
  91. ],
  92. className="two columns",
  93. style={}),
  94. html.Div([
  95. html.Button('Submit', id='submit_button', className='twelve columns',
  96. style={'background-color': '#2D91C3', 'color': 'white', 'font-size': '1em'})
  97. ],
  98. className="two columns",
  99. style={}),
  100. ],
  101. className="twelve columns",
  102. style={
  103. 'backgroundColor': '#EFEAEA',
  104. 'padding-top': '1em',
  105. 'padding-bottom': '1.5em'
  106. })
  107. ], className="nine columns", style={})
  108. ], className="twelve columns"),
  109.  
  110. # dcc.graph layout
  111.  
  112. html.Div([
  113. html.Div([
  114. dcc.Graph(id='example-graph', config={"displayModeBar": False, "scrollZoom": False})
  115.  
  116. ],
  117. className="six columns",
  118. style={'border-right': 'thin grey solid', 'border-left': 'thin grey solid',
  119. 'border-top': 'thin grey solid'}),
  120.  
  121. html.Div(id='intermediate-value1', style={'display': 'none'})
  122. ])]
  123.  
  124. @app.callback(
  125. Output("intermediate-value1", "children"),
  126. [Input("submit_button", "n_clicks")],
  127. [
  128. State("month_slider", "value"),
  129. State("demographics", "value"),
  130. State("Income", "value"),
  131. State("Frequency", "value"),
  132. ],
  133. )
  134. def clean_data(n_clicks, month_range, demo, inc, fre_cap):
  135. if n_clicks is not None and n_clicks > 0:
  136. employee_data_temp = employee_data.copy()
  137. start_date = month_range[0]
  138. end_date = month_range[1]
  139. mask1 = employee_data_temp["total_months"] == int(end_date - start_date)
  140. employee_data_temp = employee_data_temp.loc[mask1]
  141. mask2 = (
  142. (employee_data_temp["demographic"] == demo)
  143. & (employee_data_temp["freq_cap"] == fre_cap)
  144. & (employee_data_temp["total_incressions"] == inc)
  145. )
  146. employee_data_temp = employee_data_temp.loc[mask2]
  147. employee_data_temp = employee_data_temp.sort_values(by=["reach"])
  148. employee_data_temp["income_percent"] = (employee_data_temp["reach"] / 955000) * 100
  149. employee_data_temp = employee_data_temp.reset_index(drop=True)
  150. return employee_data_temp.to_json(date_format="iso", orient="split")
  151. else:
  152. return []
  153.  
  154. @app.callback(Output("example-graph", "figure"),
  155. [Input("submit_button", "n_clicks")],
  156. [State("intermediate-value1", "children"),
  157. State("Income", "value")])
  158.  
  159. def update_graph(n_clicks, employee_data_temp, inc):
  160. t.sleep(2)
  161. if n_clicks is not None and n_clicks > 0:
  162. dff = pd.read_json(employee_data_temp, orient="split")
  163. max_income = dff["income_percent"].iloc[9]
  164. max_income = max_income.round(2)
  165. trace = Scatter(
  166. y=dff["income_percent"], x=dff["inc"], line=plotly.graph_objs.scatter.Line(color="#1a2d46"), mode="lines"
  167. )
  168. layout1 = Layout(
  169. plot_bgcolor="#FFFFFF",
  170. paper_bgcolor="#FFFFFF",
  171. height=450,
  172. title="Digital Reach - " + str(max_income) + " " + "%",
  173. xaxis=dict(showgrid=True, showline=True, zeroline=True, fixedrange=True, title="Total Income"),
  174. yaxis=dict(showline=True, fixedrange=True, zeroline=True, title="Income (%)"),
  175. margin=plotly.graph_objs.layout.Margin(t=45, l=50, r=50),
  176. )
  177. return Figure(data=[trace], layout=layout1)
  178. else:
  179. return []
  180.  
  181. Traceback (most recent call last):
  182. File "C:UsersTusharDocumentsdjango_projectstvnz_dash_appsrcdash_appincrementorviews.py", line 21, in dispatcher
  183. response = server.full_dispatch_request()
  184. File "C:python37libsite-packagesflaskapp.py", line 1815, in full_dispatch_request
  185. rv = self.handle_user_exception(e)
  186. File "C:python37libsite-packagesflaskapp.py", line 1718, in handle_user_exception
  187. reraise(exc_type, exc_value, tb)
  188. File "C:python37libsite-packagesflask_compat.py", line 35, in reraise
  189. raise value
  190. File "C:python37libsite-packagesflaskapp.py", line 1813, in full_dispatch_request
  191. rv = self.dispatch_request()
  192. File "C:python37libsite-packagesflaskapp.py", line 1799, in dispatch_request
  193. return self.view_functions[rule.endpoint](**req.view_args)
  194. File "C:python37libsite-packagesdashdash.py", line 1073, in dispatch
  195. response.set_data(self.callback_map[output]['callback'](*args))
  196. File "C:python37libsite-packagesdashdash.py", line 969, in add_context
  197. output_value = func(*args, **kwargs)
  198. File "C:UsersTusharDocumentsdjango_projectstvnz_dash_appsrcdash_appincrementorrouter.py", line 699, in update_graph
  199. dff = pd.read_json(employee_data_temp, orient="split")
  200. File "C:python37libsite-packagespandasiojsonjson.py", line 413, in read_json
  201. path_or_buf, encoding=encoding, compression=compression,
  202. File "C:python37libsite-packagespandasiocommon.py", line 232, in get_filepath_or_buffer
  203. raise ValueError(msg.format(_type=type(filepath_or_buffer)))
  204. ValueError: Invalid file path or buffer object type: <class 'NoneType'>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement