Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
marcodlk authored Aug 31, 2018
1 parent 85b9397 commit 971b085
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,95 @@ for clone in clones:
clone.callbacks(State('how-many-clones', 'children'))


if __name__ == '__main__':
app.run_server(debug=True, port=5000, host='0.0.0.0')
~~~

#### examples/location.py
~~~python
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Output, Input, State
import dash_building_blocks as dbb
import json


EMPTY_MAP = {
'data': [{
'long': [],
'lat': [],
'type': 'scattergeo'
}],
'layout': {}
}


class Map(dbb.Block):

def layout(self):
return dcc.Graph(
figure=EMPTY_MAP,
id=self.register('map')
)

def callbacks(self, input_location):

@self.app.callback(
self.output('map', 'figure'),
[input_location]
)
def update_map(location):

location = json.loads(location)
long = location['longitude']
lat = location['latitude']

data = [dict(
type = 'scattergeo',
lon = [long],
lat = [lat],
text = 'Here!',
mode = 'markers',
marker = dict(
size = 8,
opacity = 0.8,
symbol = 'x',
line = dict(
width=1,
color='rgba(102, 102, 102)'
),
color = 'red',
)
)]

layout = dict(title='World Map')

return dict(data=data, layout=layout)


app = dash.Dash()
app.config.suppress_callback_exceptions = True

datastore = dbb.DataBlock(app, hide=True)

map = Map(app)

userinput = dbb.InputForm(app,
id='location',
inputs=['longitude', 'latitude'],
form_id='user-input',
db=datastore)

layout = html.Div(
children=[map.layout, userinput.layout, datastore.layout]
)

app.layout = layout

map.callbacks(datastore.input('user-input'))


if __name__ == '__main__':
app.run_server(debug=True, port=5000, host='0.0.0.0')
~~~

0 comments on commit 971b085

Please sign in to comment.