Skip to content

Commit

Permalink
.gitignore is now working
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy committed Apr 2, 2019
1 parent 9eba8bf commit 6a22018
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build
coverage
demo
dist
test
lib
*.egg-info
*__pycache__
Expand Down
128 changes: 64 additions & 64 deletions example/Run_js/Apply_ jQuery_Datatables.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import visdcc
import pandas as pd

def generate_html_table_from_df(df, id):
Thead = html.Thead(
[html.Tr([html.Th(col) for col in df.columns])]
)
Tbody = html.Tbody(
[html.Tr(
[html.Td( df.iloc[i, j], id = '{}_{}_{}'.format(id, i, j) ) for j in range(len(df.columns))]
) for i in range(len(df))]
)
return html.Table([Thead, Tbody], id = id, className = "display")

df = pd.DataFrame({'name': ['Jacky', 'Mei', 'Jay', 'Sandy', 'Jerry', 'Jimmy', 'Jeff',
'Jacky', 'Mei', 'Jay', 'Sandy', 'Jerry', 'Jimmy', 'Jeff',
'Jacky', 'Mei', 'Jay', 'Sandy', 'Jerry', 'Jimmy', 'Jeff'],
'age': [18, 71, 14, 56, 22, 28, 15,
18, 71, 14, 56, 22, 28, 15,
18, 71, 14, 56, 22, 28, 15]}, columns = ['name', 'age'])

external_scripts = ['https://code.jquery.com/jquery-3.3.1.min.js',
'https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.js']
external_stylesheets = ['https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.css']

app = dash.Dash(external_scripts = external_scripts,
external_stylesheets = external_stylesheets)

app.layout = html.Div([
html.Button('apply datatable', id = 'button'),
visdcc.Run_js(id = 'javascript'),
html.Br(),
html.Div(
generate_html_table_from_df(df, id = 'datatable'),
style = {'width': '40%'}
),
html.H1(id = 'output_div')
])

@app.callback(
Output('javascript', 'run'),
[Input('button', 'n_clicks')])
def myfun(x):
if x:
return "$('#datatable').DataTable()"
return ""

@app.callback(
Output('output_div', 'children'),
[Input('datatable_{}_{}'.format(i, j), 'n_clicks') for i in range(len(df)) for j in range(len(df.columns))])
def myfun(*args):
ctx = dash.callback_context
if not ctx.triggered or ctx.triggered[0]['value'] is None: return ""
input_id = ctx.triggered[0]['prop_id'].split('.')[0]
row = input_id.split('_')[1]
col = input_id.split('_')[2]
return "you click on row {} col {}".format(row, col)

if __name__ == '__main__':
app.run_server(debug=True)
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import visdcc
import pandas as pd

def generate_html_table_from_df(df, id):
Thead = html.Thead(
[html.Tr([html.Th(col) for col in df.columns])]
)
Tbody = html.Tbody(
[html.Tr(
[html.Td( df.iloc[i, j], id = '{}_{}_{}'.format(id, i, j) ) for j in range(len(df.columns))]
) for i in range(len(df))]
)
return html.Table([Thead, Tbody], id = id, className = "display")

df = pd.DataFrame({'name': ['Jacky', 'Mei', 'Jay', 'Sandy', 'Jerry', 'Jimmy', 'Jeff',
'Jacky', 'Mei', 'Jay', 'Sandy', 'Jerry', 'Jimmy', 'Jeff',
'Jacky', 'Mei', 'Jay', 'Sandy', 'Jerry', 'Jimmy', 'Jeff'],
'age': [18, 71, 14, 56, 22, 28, 15,
18, 71, 14, 56, 22, 28, 15,
18, 71, 14, 56, 22, 28, 15]}, columns = ['name', 'age'])

external_scripts = ['https://code.jquery.com/jquery-3.3.1.min.js',
'https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.js']
external_stylesheets = ['https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.css']

app = dash.Dash(external_scripts = external_scripts,
external_stylesheets = external_stylesheets)

app.layout = html.Div([
html.Button('apply datatable', id = 'button'),
visdcc.Run_js(id = 'javascript'),
html.Br(),
html.Div(
generate_html_table_from_df(df, id = 'datatable'),
style = {'width': '40%'}
),
html.H1(id = 'output_div')
])

@app.callback(
Output('javascript', 'run'),
[Input('button', 'n_clicks')])
def myfun(x):
if x:
return "$('#datatable').DataTable()"
return ""

@app.callback(
Output('output_div', 'children'),
[Input('datatable_{}_{}'.format(i, j), 'n_clicks') for i in range(len(df)) for j in range(len(df.columns))])
def myfun(*args):
ctx = dash.callback_context
if not ctx.triggered or ctx.triggered[0]['value'] is None: return ""
input_id = ctx.triggered[0]['prop_id'].split('.')[0]
row = input_id.split('_')[1]
col = input_id.split('_')[2]
return "you click on row {} col {}".format(row, col)

if __name__ == '__main__':
app.run_server(debug=True)

11 changes: 0 additions & 11 deletions test/main.js

This file was deleted.

17 changes: 0 additions & 17 deletions visdcc.egg-info/PKG-INFO

This file was deleted.

12 changes: 0 additions & 12 deletions visdcc.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion visdcc.egg-info/dependency_links.txt

This file was deleted.

1 change: 0 additions & 1 deletion visdcc.egg-info/top_level.txt

This file was deleted.

0 comments on commit 6a22018

Please sign in to comment.