I'm trying to include a banner at the top of a dashboard. Currently the top section of the contain display cards and a sidebar. Is there a way to push the columns down and include a banner above them.
I'm also hoping to extend the height of the right graph to it is the same as both graphs on the left.
I've attached a screenshot of the current layout with some arrows highlighting the intended layout.
from dash import Dash
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.express as px
# generic card
card = dbc.Card(
[
dbc.CardHeader("This is the header"),
dbc.CardBody(
[
html.H4("Card title", className="card-title"),
html.P("This is some card text", className="card-text"),
]
),
dbc.CardFooter("This is the footer"),
],
className='text-center m-4'
)
external_stylesheets = [dbc.themes.SPACELAB, dbc.icons.BOOTSTRAP]
app = Dash(__name__, external_stylesheets = external_stylesheets)
# Set up the layout with a single graph
app.layout = dbc.Container([
dbc.Row([
# to be used as a sidebar
dbc.Col(html.Div("stuff", className="bg-secondary h-100"), width=2),
dbc.Col([
dbc.Row([
dbc.Col(card),
dbc.Col(card),
dbc.Col(card)
]),
dbc.Row([
dbc.Col(dcc.Graph(), style={
"padding-top": "10px",
"padding-bottom": "10px",
},),
]),
dbc.Row([
dbc.Col([dcc.Graph()]),
]),
], width=5),
dbc.Col([
dbc.Row([
dbc.Col(card),
dbc.Col(card),
dbc.Col(card),
]),
dbc.Row([
dbc.Col([dcc.Graph()]),
], className="h-100"),
], width=5),
])
], fluid=True)
if __name__ == '__main__':
app.run(debug=True)
I think you should add one more row above cards and you will need to merge 3 graph in one Row with 2 columns and change height of graph on the right.
Please check below code:
from dash import Dash
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.express as px
df = px.data.gapminder()
fig = px.area(df, x="year", y="pop", color="continent", line_group="country")
# generic card
card = dbc.Card(
[
dbc.CardHeader("This is the header"),
dbc.CardBody(
[
html.H4("Card title", className="card-title"),
html.P("This is some card text", className="card-text"),
]
),
dbc.CardFooter("This is the footer"),
],
className='text-center m-4'
)
external_stylesheets = [dbc.themes.SPACELAB, dbc.icons.BOOTSTRAP]
app = Dash(__name__, external_stylesheets = external_stylesheets)
# Set up the layout with a single graph
app.layout = dbc.Container([
dbc.Row([
html.Img(src=r'assets/hong-kong-skyline-panorama.jpg', alt='image')
]),
dbc.Row([
# to be used as a sidebar
dbc.Col(html.Div("stuff", className="bg-secondary h-100"), width=2),
dbc.Col([
dbc.Row([
dbc.Col(card),
dbc.Col(card),
dbc.Col(card),
dbc.Col(card),
dbc.Col(card),
dbc.Col(card)
]),
dbc.Row([
dbc.Col([dbc.Card(dcc.Graph(figure=fig),style={'height':400}),
dbc.Card(dcc.Graph(figure=fig),style={'height':400})
], width=6),
dbc.Col([dbc.Card(dcc.Graph(figure=fig,style={'height':800}),style={'height':800})], width=6),
]),
], width=10),
], className='p-2 align-items-stretch')
], fluid=True)
if __name__ == '__main__':
app.run(debug=True)
And here is the result:
Related
from jupyter_plotly_dash import JupyterDash
import dash
import dash_leaflet as dl
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import dash_table
from dash.dependencies import Input, Output
import base64
import os
import numpy as np
import pandas as pd
from pymongo import MongoClient
from Module import AnimalShelter
username = "username"
password = "password"
animal = AnimalShelter(username, password)
df = pd.DataFrame.from_records(animal.readAll({}))
#########################
# Dashboard Layout / View
#########################
app = JupyterDash('Dash DataTable Only')
image_filename = 'Grazioso Salvare Logo.png' # customer image
encoded_image = base64.b64encode(open(image_filename, 'rb').read())
app.layout = html.Div([
html.Center(html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode()))),
html.Center(html.B(html.H1('Kristopher Collis'))),
html.Hr(),
html.Div(
#Radio Items to select the rescue filter options
dcc.RadioItems(
id='filter-type',
),
),
html.Hr(),
dash_table.DataTable(
id='datatable-id',
columns=[
{"name": i, "id": i, "deletable": False, "selectable": True} for i in df.columns
],
data=df.to_dict('records'),
editable=False,
filter_action="native",
sort_action="native",
sort_mode="multi",
column_selectable=False,
row_selectable="multi",
row_deletable=False,
selected_columns=[],
selected_rows=[],
page_action="native",
page_current= 0,
page_size= 10,
),
html.Hr(),
html.Div(className='row',
style={'display' : 'flex'},
children =[
html.Div(
id='graph-id',
className='col s12 m6'
),
html.Div(
id = 'map-id',
className='col s12 m6'
),
]
),
html.Br(),
html.Hr(),
])
#############################################
# Interaction Between Components / Controller
#############################################
# #callback for Piechart
#app.callback(
Output('graph-id', "children"),
[Input('datatable-id', "derived_viewport_data")])
#fucntion for update_graph
def update_graphs(viewData):
dff = pd.DataFrame.from_dict(viewData)
names = dff['breed'].value_counts().keys().tolist()
values = dff['breed'].value_counts().tolist()
return[
dcc.Graph(
id = 'graph-id',
fig = px.pie(data_frame = dff,values = values,names = names,
color_discrete_sequence = px.colors.sequential.RdBu,width = 800,height = 500
)
)
]
#callback for update_map
#app.callback(
Output('map-id', "children"),
[Input('datatable-id', "derived_viewport_data"),
Input('datatable-id', 'selected_rows'),
Input('datatable-id', 'selected_columns')])
#update_function with variables
def update_map(viewData, selected_rows, selected_columns):
dff = pd.DataFrame.from_dict(viewData)
#width, height of map, center of map, and how much zoom do you want for map
return [dl.Map(style = {'width': '1000px', 'height': '500px'}, center = [30.75,-97.48], zoom = 7,
children = [dl.TileLayer(id = "base-layer-id"),
#marker with tool tip and popup
dl.Marker(position=[(dff.iloc[selected_rows[0],13]), (dff.iloc[selected_rows[0],14])], children=[
dl.Tooltip(dff.iloc[selected_rows[0],4]),
dl.Popup([
html.H4("Animal Name"),
html.P(dff.iloc[selected_rows[0],9]),
])
])
])
]
app
When I run the program, the geoloction map populates but not the graph. I was able to populate the graph a couple of times finding information on plotly, and other documentation. I have spent a while trying to figure out why the graph will not display again. I did attempt to use fig.show() at the bottom of the update_graphs function. I am not sure if that was what made it work, but I am stumped. I am respectfully requesting help finding the error in the def update_graphs function.
So i have this Grafana dashboard that i'm making up using jq and different files. The problem i end up with is that when you export the json produced by Grafana, it will export it the way it sees it currently. Example:
[
{
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 22
},
"panels": []
},
{
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 43
},
"panels": []
},
{
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 17
},
"panels": []
}
]
But the problem is that the grid positions need to be properly incremented (the Y's) so that when you reload the Grafana dashboards, the panels nested under row panels get set to their proper locations. If you have a sub panel that has a gridPos.y that is lower than the row panel's gridPos.y then it will appear in a weird location.
I tried using reduce and foreach but i'm not super good with these constructs yet. For example, i tried this:
[
1 as $currentY |
foreach .[] as $item (
[];
(. + [$item * {"gridPos": {"y": ($currentY + 1)}}]);
. | last
)
]
But i can't figure out how to increment $currentY within the loop to achieve proper incrementation. The objective would be to nest a second foreach/reduce to continue setting and incrementing $currentY in all panels and sub panels.
Can you help? Thanks!
Note: I know i should use reduce when using .|last, this was just the last try. Don't point that out, i want guidance on how to increment $currentY in the current approach.
With your existing approach as such, you need to reference the y field in each $item processed and increment its value, rather than the predefined value of $currentY, i.e.
[
1 as $currentY |
foreach .[] as $item (
[];
(. + [$item * {"gridPos": {"y": ($currentY + $item.gridPos.y )}}]);
last
)
]
which again could be written as
[
1 as $currentY |
foreach .[] as $item (
[];
(. + [ $item | .gridPos.y += $currentY ]);
last
)
]
which again could be written with a simple walk expression
1 as $currentY |
walk ( if type == "object" and has("gridPos") then .gridPos.y += $currentY else . end )
I want to centre the top drop down here within the blue background block:
https://imgur.com/a/BfWxtes
I've tried a lot of different things including following this guide:
https://www.w3schools.com/howto/howto_css_image_center.asp. I've also tried adding a float:center argument, but I cant for the life of me get it to work.
Here is the relevant part of the code I've written: (I want to centre the elements that come under the '# First row of the dropdown menus' section)
html.Div([
# First row of the dropdown menus
html.Div([
html.Div([
dcc.Dropdown(
id="court_dd_0",
options=[
{'label': i, 'value': i} for i in sorted(list(crest['court_name'].unique()))
],
value = 'Aylesbury Crown Court',
#placeholder='[Placeholder] John Doe',
),
], style={'width': '50%',
'display': 'block',
'margin-left': 'auto',
'margin-right': 'auto',
'textAlign': 'center'}, className='six columns'),
], className='row'),
# Second row of the dropdown menus
html.Div([
html.Div([
dcc.Dropdown(
id="offence_group_dd_2",
options=[
{'label': i, 'value': i} for i in sorted(list(df_gb_offences.offence_ho_group_desc_mso.unique()))
],
value = None,
placeholder='Select breakdown by offence group',
),
], style={'padding': 10}, className="six columns"),
html.Div([
dcc.Dropdown(
id="offence_code_dd_3",
options=[
{'label': i, 'value': i} for i in sorted(list(crest.offence_ho_code_desc_mso.unique()))
],
#value = None,
placeholder='Select breakdown by offence',
),
], style={'padding': 10}, className="six columns"),
], className='row'),
# Third row of the dropdown menus
html.Div([
html.Div([
dcc.Slider(
id='year_slider_0',
min=crest['year'].min(),
max=crest['year'].max(),
value=crest['year'].max(),
marks={str(year): str(year) for year in crest['year'].unique()}
),
], className="twelve columns"),
], style={'padding': 10}, className='row'),
# End of third row of the drop down menus
], style={
'textAlign': 'center',
'margin':25,
'backgroundColor': colors['background'],
'width': '95%',
'height': '100%',
'display': 'inline-block',
'padding': 10
}),
It looks like you specified offence_group_dd_2 to take up 6 columns in the row, which is exactly it appears to be doing. Try removing the "six columns" class names.
I can't figure out, why subgraph doesn't work here:
digraph virtPfr {
node [
shape=box
]
Start [
style=rounded,
label="create folder profiles"
]
subgraph asd {
label = "copy files from other profiles"
cpIfDestFilesExist [
label = "Check for file existance"
]
Cp [
label = "Copy"
]
}
Start -> asd
cpIfDestFilesExist -> Start
cpIfDestFilesExist -> Cp
}
but this code works:
digraph G {
node [
shape = "record"
]
Animal [
label = "Animal name and age"
]
subgraph clusterAnimalImpl {
label = "Package animal.tmpl"
Dog [
label = "Dog name and age"
]
Cat [
label = "Cat name and age"
]
}
Dog -> Animal
Cat -> Animal
Dog -> Cat
}
I don't understand, what's different on the top graph, in comparison to the bottom graph, that the bottom works, but the top doesn't. I've already pulled my eyes out. I don't see the problem here.
Please, help
A couple of issues:
Sub-graph names have to start with the keyword cluster.
You can't connect edges directly to a sub-graph, instead you can use the lhead/ltail workaround described here.
For your graph, it could like as follows:
digraph virtPfr {
graph [compound=true]
node [
shape=box
]
Start [
style=rounded,
label="create folder profiles"
]
subgraph cluster_asd {
label = "copy files from other profiles"
cpIfDestFilesExist [
label = "Check for file existance"
]
Cp [
label = "Copy"
]
}
Start -> cpIfDestFilesExist [lhead=cluster_asd]
cpIfDestFilesExist -> Start
cpIfDestFilesExist -> Cp
}
Which generates the following output:
I am trying to display line segments on a map using GMapPlot. The lines flashes in red and then disappears, in jupyter notebook. This is my code (some decimals left out):
map_options = GMapOptions(lat=37.88, lng=-122.23, map_type="roadmap", zoom=10)
plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options
)
source = ColumnDataSource( data = dict(
y=[ 37.762260 ],
x=[-121.96226],
ym01=[37.762290 ],
xm01=[-121.96189 ]
)
segment = Segment(x0="x", y0="y", x1="xm01", y1="ym01",line_color="green", line_width=100)
plot.add_glyph(source, segment)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
output_notebook()
show(plot)
UPDATE This issue is resolved in https://github.com/bokeh/bokeh/pull/8240 which will be part of Bokeh 1.0
I've tried to reproduce with updated code:
from bokeh.io import show
from bokeh.models import GMapOptions, ColumnDataSource
from bokeh.plotting import figure, gmap
map_options = GMapOptions(lat=37.88, lng=-122.23, map_type="roadmap", zoom=10)
plot = gmap(google_api_key=API_KEY, map_options=map_options)
source = ColumnDataSource( data = dict(
y=[ 37.762260 ],
x=[-121.96226],
ym01=[37.762290 ],
xm01=[-121.96189 ]
))
plot.segment(x0="x", y0="y", x1="xm01", y1="ym01",line_color="green", line_width=10, source=source)
show(plot)
And can confirm that the segment does not show up. Slightly changing to show circles does work, so I have to conclude that this is a bug of some sort. Please file a detailed GitHub issue to report this bug.