Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. from dash_table import DataTable
  2.  
  3. def lineplot(id, df, cols, title=None, xlabel=None, ylabel=None, x=None,
  4. xaxis_type=None, yaxis_type=None, plotly_config=plotly_config,
  5. ):
  6.  
  7. if x is None:
  8. x_values = df.index
  9. xlabel = df.index.name
  10. else:
  11. x_values = df[x]
  12.  
  13. data = [{
  14. 'x': x_values,
  15. 'y': df[col],
  16. 'name': col } for col in cols]
  17.  
  18. layout = go.Layout(
  19. title=go.layout.Title(
  20. text=title,
  21. xref='paper',
  22. xanchor='center'
  23. ),
  24. xaxis = go.layout.XAxis(
  25. title=go.layout.xaxis.Title(
  26. text=xlabel,
  27. font=plotly_config['font'],
  28.  
  29. ),
  30. type=xaxis_type
  31. ),
  32. yaxis=go.layout.YAxis(
  33. title=go.layout.yaxis.Title(
  34. text=ylabel,
  35. font=plotly_config['font'],
  36. ),
  37. type=yaxis_type
  38. ),
  39. showlegend=True
  40. )
  41.  
  42.  
  43. return dcc.Graph(
  44. id=id,
  45. figure={'data': data,
  46. 'layout': layout},
  47. style={"max-width": "600px",
  48. "margin": "auto",
  49. "display": "inline-block"})
  50.  
  51. def table(id, df):
  52. dt = DataTable(
  53. id=id,
  54. data=df.to_dict('records'),
  55. columns=[{"name": i,
  56. "id": i,
  57. "deletable": True,
  58. "searchable": True} for i in df.columns],
  59. sorting=True,
  60. style_cell={
  61. 'minWidth': '0px',
  62. 'maxWidth': '180px',
  63. 'whiteSpace': 'no-wrap',
  64. 'overflow': 'hidden',
  65. 'textOverflow': 'ellipsis'},
  66. style_table={'overflowX': 'scroll'},
  67. row_deletable=True,
  68. pagination_mode="fe",
  69. pagination_settings={
  70. "displayed_pages": 1,
  71. "current_page": 0,
  72. "page_size": 15},
  73. navigation="page"
  74. )
  75. return dt
  76.  
  77. app = dash.Dash(__name__)
  78. app.layout = html.Div(children=[
  79. table(id='table', df=pd.DataFrame(...)),
  80. lineplot(id='plot',...)
  81. ])
  82.  
  83. @app.callback(Output('plot', 'data'),
  84. [Input('table', 'data')])
  85. def update_graph(data):
  86. return pd.DataFrame(data)
  87.  
  88. if __name__ == '__main__':
  89. app.run_server(port=8888, debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement