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.
Related
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:
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'm trying to plot a dendrogram using VegaLite. The plot is almost complete, but there is just one thing mixing, which are the axis labels corresponding to the point id. In the figure I plotted, the axis is ordered from 1 to 40. I have a dictionary with the corresponding labels, e.g. if value is 1 then the label is "point10", if value is 30 then label is "point5" and so on. Hence, what I'd like to do is to replace the numbers for the label.
Is it possible to do this in VegaLite? I haven't found a way by reading the Docs.
You can just provide the field of your pointLabels in x-axis and then provide sort with field of value, with this you will be able to see the pointLabels as labels and the ordering will be displayed as per your values. Refer the below example of sorting on a Name field or check the editor.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Drag a rectangular brush to show (first 20) selected points in a table.",
"data": {"url": "data/cars.json"},
"transform": [
{"window": [{"op": "row_number", "as": "row_number"}]},
{"calculate": "'My'+datum.Name", "as": "alias"}
],
"params": [{"name": "brush", "select": "interval"}],
"mark": "bar",
"encoding": {
"x": {
"field": "Name",
"type": "nominal",
"stack": false,
"sort": {"field": "row_number", "order": "ascending"}
},
"y": {"field": "Miles_per_Gallon", "stack": false, "type": "quantitative"},
"color": {
"condition": {"param": "brush", "field": "Cylinders", "type": "ordinal"},
"value": "grey"
}
}
}
Unfortunately, I was not able to solve this by modifying the axis. Although, I did manage a solution. It's not the "correct" way, since what I do is to actually erase the axis, and add a "text" marker with the the labels, and I place it where the axis was.
If anyone is interested, here is a gist with the implementation: https://gist.github.com/davibarreira/74c4274333ac51bbeed627deeb631195
I want to select all l labelled vertices along with their t,n labelled vertices grouped by their neighbours. Also I want to apply a limit on the length of the neighbours. For ex for neighbour limit = 2 something like below should be output.
[
{"l1",{[t1,t2]}, {}},
{"l2",{[t3]}, {[n1]}},
{"l3",{[]}, {[n2,n3]}}
]
For ex for neighbour limit = 1 something like below should be output.
[
{"l1",{[t1,t2]}, {}},
{"l2",{[t3]}, {[n1]}},
{"l3",{[]}, {[n2]}}
]
grelify link https://gremlify.com/xun4v83y54/2
g.addV('Vertex').as('1').property(single, 'name', 'l1').property(single, 'label', 'l').
addV('Vertex').as('2').property(single, 'name', 'l2').property(single, 'label', 'l').
addV('Vertex').as('3').property(single, 'name', 'l3').property(single, 'label', 'l').
addV('Tag').as('4').property(single, 'name', 't1').property(single, 'label', 't').
addV('Tag').as('5').property(single, 'name', 't2').property(single, 'label', 't').
addV('Tag').as('6').property(single, 'name', 't3').property(single, 'label', 't').
addV('neighbour1').as('7').property(single, 'name', 'n1').property(single, 'label', 'n').
addV('neighbour2').as('8').property(single, 'name', 'n2').property(single, 'label', 'n').
addV('neighbour3').as('9').property(single, 'name', 'n3').property(single, 'label', 'n').
addE('connected').from('1').to('4').
addE('connected').from('1').to('5').
addE('connected').from('2').to('6').
addE('connected').from('2').to('7').
addE('connected').from('3').to('8')
addE('connected').from('3').to('9')
For this output you can try doing something like this:
g.V().hasLabel('l').
group().by('name').
by(out('connected').fold()
project('t', 'n').
by(unfold().hasLabel('t').limit(1).values('name').fold()).
by(unfold().hasLabel('n').limit(1).values('name').fold())
.unfold().select(values).fold())
You can change the limit to be the max number of neighbors you want from each type.
example: https://gremlify.com/ecw6j2ajh5p
I have the following data
new Chart(ctx2, {
type: 'bar',
data: {
labels: $scope.teamGraphAssociateName,
datasets: [{
data: $scope.teamGraphAgileRewards,
backgroundColor: $scope.backgroundColors,
borderWidth: 1.5
}
]
}
});
This data gets success data of all the associates name on the (X axis) from labels.
For the $scope.teamGraphAgileRewards in console i'm getting data like this:
(3) [Array(1), Array(2), Array(1)]
0: [7]
1: (2) [2, 3]
2: [10]
length: 3
I'm getting the grap like this.(only the last array [10] is getting visible on graph)
Y
|
|
|
| 10
|_______________ X
ASS1 ASS2 ASS3
(labels)
But I want this data to be visible on stacked bar graph like this.
Y
|
| 3
|
| 7 2 10
|_______________ X
ASS1 ASS2 ASS3
(labels)
Well, you will need to rearange your data. Data structure of chart is different than this you are sending to chart. See example:
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["ASS1", "ASS2", "ASS3"],
datasets: [{
stack: 'Stack 0',
data: [7, 3, 10],
backgroundColor: 'blue'
},
{
stack: 'Stack 0',
data: [0, 2, 0],
backgroundColor: 'green'
}]
},
options: {
legend: {
display: false
},
responsive: false,
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true
}]
}
}
});
That's how your chart should look like. Each data what you add to dataset is sent to labels, so when you send arrays in array it can't be recognized, that you want to add multiple values for one label. Group your values in way, that you have 3 values for one dataset (['ASS1value', 'ASS2value', 'ASS3value']), like I've added in sample.