how to use overlay in plotly dashboard bootstrap? - python

how to use overlay in carousel plotly dashboard bootstrap?
I'm using bootstrap for python (dash_bootstrap_components - dbc), and I have an Carousel tag with three images and some text that I want to overlay to the right of my carousel.
Current
Desired: Floating
Here is the code:
App:
from dash import Dash, html
import dash_bootstrap_components as dbc
from components.callbacks import modals
app = Dash(__name__, title = 'page test',
external_stylesheets=[dbc.themes.BOOTSTRAP]
)
app.layout = dbc.Container([
dbc.Container([
dbc.Carousel(
items=[
{"key": "1", "src": "/assets/images/NY.jpg"},
{"key": "2", "src": "/assets/images/tokio.jpg"},
{"key": "3", "src": "assets/images/paris.jpg"},
],
controls=False,
indicators=False,
interval=2000,
ride="carousel",
),
dbc.Container([
dbc.Container([
dbc.Row(children=[
dbc.Col([
html.H1("Title", className="sub_title"),
html.P("Lorem ipsum dolor sit amet consectetur, adipisicing elit. Adipisci, illo eos ad \
inventore reiciendis alias impedit repellendus dolorum. Itaque cum perspiciatis nihil \
mollitia adipisci est reprehenderit a, autem placeat qui. Fugit?"),
modals,
],width={"size": 6, "offset": 6}),
], className="row text-center"),
]),
], id="overlay"),
], fluid=True, id="main", className='main'),
], fluid=True, class_name='home')
if __name__ == '__main__':
app.run_server(debug=True)
CSS:
.home{
padding: 0px 0px 0px 0px;
}
.main{
padding: 0px 0px 0px 0px;
}
#main .carousel-inner img{
max-height: 70vh;
object-fit: cover;
filter: grayscale(70%);
}
#carousel {
position: relative;
}
#carousel .overlay {
z-index: 1;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgb(0,0,0,0.5);
color: white;
}
What's the way to do this?

Maybe using className="fixed-top" could help. I don't have your modals so I used dbc.Card. Please check below code:
from dash import Dash, html
import dash_bootstrap_components as dbc
df = px.data.gapminder()
fig = px.area(df, x="year", y="pop", color="continent", line_group="country")
app = Dash(__name__, title = 'page test',
external_stylesheets=[dbc.themes.BOOTSTRAP]
)
app.layout = dbc.Container([
dbc.Row([
dbc.Col([
dbc.Card([
dbc.CardBody([
html.H1("Title", className="sub_title"),
html.P("Lorem ipsum dolor sit amet consectetur, adipisicing elit. Adipisci, illo eos ad \
inventore reiciendis alias impedit repellendus dolorum. Itaque cum perspiciatis nihil \
mollitia adipisci est reprehenderit a, autem placeat qui. Fugit?")
])
])
],width={"size": 3, "offset": 9})
], className="fixed-top"),
dbc.Row([
dbc.Carousel(
items=[
{"key": "1", "src": "/assets/1_times_square_night_2013.jpg"},
{"key": "2", "src": "/assets/1_times_square_night_2013.jpg"},
{"key": "3", "src": "assets/1_times_square_night_2013.jpg"},
],
controls=False,
indicators=False,
interval=2000,
ride="carousel",
),
]),
dbc.Row([
dbc.Col([
dcc.Graph(figure=fig)
])
]),
dbc.Row([
dbc.Col([
dcc.Graph(figure=fig)
])
])
], fluid=True)
if __name__ == '__main__':
app.run_server(debug=True)

Related

Reduce white space below footer Shiny for Python

I'm creating a shiny app with Python, but for some reason there's a lot of white space below the footer. The body uses 100% of the height, but the ui_fluid makes the content stick to the top.
Anyone knows how to fix it?
from shiny import App, render, ui
from shiny.types import ImgData
from model.panel import panel_ui
from model.file import css_file, img_file
app_ui = ui.page_fluid(
{"class": "p-4"},
ui.head_content(
ui.tags.meta(name="viewport",
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalabel=no"),
ui.tags.style(css_file("src/static/css/body.css")),
ui.tags.style(css_file("src/static/css/sidebar.css")),
ui.tags.style(css_file("src/static/css/footer.css")),
),
ui.layout_sidebar(
ui.panel_sidebar(
ui.navset_tab_card(
ui.nav(
"Quality assurance",
ui.input_file("file1", "Choose forward fastaq file",
accept=[".fastq"], multiple=False),
ui.input_file("file2", "Choose reverse fastaq file",
accept=[".fastq"], multiple=False),
ui.input_slider("q_threshold", "Qual threshold:",
min=0, max=40, value=20),
ui.input_slider("l_threshold", "Length threshold:",
min=0, max=40, value=20),
ui.input_select(
"quality_type",
"Choose quality type",
["illumina", "sanger", "solexa"]
),
ui.input_checkbox(
"five_prime", "Five prime trimming", True),
),
ui.nav(
"Alligment",
ui.input_file("file3", "Choose reference genome file",
accept=[".fa"], multiple=False),
),
ui.nav(
"Post-alligment",
ui.input_select(
"sequence_read",
"Choose sequence read type",
["short", "long"]
),
),
),
panel_ui(
{"class": "card my-3 mb-0"},
ui.p(
"Make sure all of the requirements are satisfied before running the app"),
ui.div(
{"class": "text-center"},
ui.input_action_button(
"run", "Run app", class_="btn-primary w-50"
)
)
)
),
# code over here in development ...
ui.panel_main(
),
),
ui.row(
ui.column(12,
ui.div({"class": "footer mt-3 p-3 w-100"},
ui.output_image("logo_1", inline=True),
ui.output_image("logo_2", inline=True),
ui.p("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget imperdiet nisi, eget dapibus erat. Proin a orci id mi cursus cursus nec a purus. Ut lacus lectus, lobortis in suscipit quis, luctus pharetra ipsum. Etiam mollis vestibulum sem non bibendum.")
),
)
)
)
def server(input, output, session):
# output
# render.image
def logo_fcv():
return img_file("src/static/images/logo-1.png", "150px")
# output
# render.image
def logo_udes():
return img_file("src/static/images/logo-2.png", "200px")
app = App(app_ui, server)
body.css
body {
height: 100%;
width: 100%;
}
footer.css
.footer {
background-color: #dee2e6;
position: relative;
width: 100%;
text-align: center;
}
#media screen and (max-width: 725px) {
.footer {
display: grid;
}
.footer p {
padding-top: 1em;
}
}
sidebar.css (paddint: 0, because ui.panel_sidebar makes it look like there's a bar inside the other)
.well {
padding: 0;
}
I tried forcing x height and minimum-height in the css, using another layout and a sticky footer (that leaves even more space in the middle šŸ˜’)

Make PDF using Python and Amcharts5

I am following the tutorial on https://www.amcharts.com/docs/v5/tutorials/creating-multi-content-pdf-export/ in order to make a PDF using Amcharts5.
This is the layout of my files:
src/input/chart.html
src/input/javascript.js
src/input/style.css
src/output/.gitkeep
src/make_pdf_from_input.py
I want to use chart.html, javascript.js and style.css to make a PDF when I run the script make_pdf_from_input.py.
src/input/chart.html
<html lang="en-US">
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
<script src="https://cdn.amcharts.com/lib/5/percent.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Dataviz.js"></script>
<div class="main">
<h1>In accumsan velit in orci tempor</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sem quam, sodales ac volutpat sed, vestibulum id quam. Sed quis arcu non elit fringilla mattis. Sed auctor mi sed efficitur vehicula. Sed bibendum odio urna, quis lobortis dui luctus ac. Duis eu lacus sodales arcu tincidunt ultrices viverra a risus. Vivamus justo massa, malesuada quis pellentesque ut, placerat in massa. Nunc bibendum diam justo, in consequat ipsum fringilla ac. Praesent porta nibh ac arcu viverra, at scelerisque neque venenatis. Donec aliquam lorem non ultrices ultrices. Aliquam efficitur eros quis tortor condimentum, id pellentesque metus iaculis. Aenean at consequat neque, a posuere lectus. In eu libero magna. Pellentesque molestie tellus nec nisi molestie, eu dignissim lacus tristique. Sed tellus nulla, suscipit a velit non, mattis dictum metus. Curabitur mi mi, convallis nec libero quis, venenatis vestibulum ante.</p>
<h2>Aliquam lacinia justo</h2>
<div id="chartdiv" class="chart"></div>
<h2>Phasellus suscipit in diam a interdum</h2>
<table>
<tr>
<th>USA</th>
<th>Japan</th>
<th>France</th>
<th>Mexico</th>
</tr>
<tr>
<td>2500</td>
<td>1900</td>
<td>2200</td>
<td>1200</td>
</tr>
<tr>
<td>800</td>
<td>1200</td>
<td>990</td>
<td>708</td>
</tr>
<tr>
<td>2100</td>
<td>2150</td>
<td>900</td>
<td>1260</td>
</tr>
</table>
<h2>Duis sed efficitur mauris</h2>
<div>
<div class="col">
<div id="chartdiv2" class="chart"></div>
</div>
<div class="col">
<div id="chartdiv3" class="chart"></div>
</div>
</div>
<br>
<h2>Aliquam semper lacinia</h2>
<div id="chartdiv4" class="chart"></div>
<p>Maecenas congue leo vel tortor faucibus, non semper odio viverra. In ac libero rutrum libero elementum blandit vel in orci. Donec sit amet nisl ac eros mollis molestie. Curabitur ut urna vitae turpis bibendum malesuada sit amet imperdiet orci. Etiam pulvinar quam at lorem pellentesque congue. Integer sed odio enim. Maecenas eu nulla justo. Sed quis enim in est sodales facilisis non sed erat. Aenean vel ornare urna. Praesent viverra volutpat ex a aliquet.</p>
<p>Fusce sed quam pharetra, ornare ligula id, maximus risus. Integer dignissim risus in placerat mattis. Fusce malesuada dui ut lectus ultricies, et sollicitudin nisl placerat. In dignissim elit in pretium lobortis. Fusce ornare enim at metus laoreet, ut convallis elit lacinia. Maecenas pharetra aliquet mi. Nulla orci nunc, egestas id nisi ut, volutpat sollicitudin mi.</p>
</div>
</body>
</html>
src/input/javascript.js
/**
* ---------------------------------------
* This demo was created using amCharts 5.
*
* For more information visit:
* https://www.amcharts.com/
*
* Documentation is available at:
* https://www.amcharts.com/docs/v5/
* ---------------------------------------
*/
/**
* Chart 1
*/
// Create root element
var root = am5.Root.new("chartdiv");
// Set themes
root.setThemes([
am5themes_Animated.new(root),
am5themes_Dataviz.new(root)
]);
var data = [{
date: new Date(2018, 0, 1).getTime(),
value: 450,
value2: 362,
value3: 699
}, {
date: new Date(2018, 0, 2).getTime(),
value: 269,
value2: 450,
value3: 841
}, {
date: new Date(2018, 0, 3).getTime(),
value: 700,
value2: 358,
value3: 699
}, {
date: new Date(2018, 0, 4).getTime(),
value: 490,
value2: 367,
value3: 500
}, {
date: new Date(2018, 0, 5).getTime(),
value: 500,
value2: 485,
value3: 369
}, {
date: new Date(2018, 0, 6).getTime(),
value: 550,
value2: 354,
value3: 250
}, {
date: new Date(2018, 0, 7).getTime(),
value: 420,
value2: 350,
value3: 600
}];
// Create chart
var chart = root.container.children.push(
am5xy.XYChart.new(root, {
paddingBottom: 20
})
);
// Create axes
var xAxis = chart.xAxes.push(
am5xy.DateAxis.new(root, {
maxDeviation: 0.1,
groupData: false,
baseInterval: {
timeUnit: "day",
count: 1
},
renderer: am5xy.AxisRendererX.new(root, {
minGridDistance: 50
})
})
);
xAxis.get("renderer").labels.template.set("forceHidden", true);
var yAxis = chart.yAxes.push(
am5xy.ValueAxis.new(root, {
maxDeviation: 0.1,
renderer: am5xy.AxisRendererY.new(root, {})
})
);
yAxis.get("renderer").labels.template.set("forceHidden", true);
// Add series
function createSeries(field) {
var series = chart.series.push(
am5xy.LineSeries.new(root, {
minBulletDistance: 10,
xAxis: xAxis,
yAxis: yAxis,
valueYField: field,
valueXField: "date",
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal",
labelText: "{valueY}"
})
})
);
series.strokes.template.setAll({
strokeWidth: 3
});
series.bullets.push(function () {
return am5.Bullet.new(root, {
sprite: am5.Circle.new(root, {
radius: 7,
fill: series.get("fill"),
stroke: root.interfaceColors.get("background"),
strokeWidth: 2
})
});
});
series.data.setAll(data);
}
createSeries("value");
createSeries("value2");
createSeries("value3");
/**
* Chart 2
*/
// Create root element
var root2 = am5.Root.new("chartdiv2");
// Set themes
root2.setThemes([
am5themes_Animated.new(root2),
am5themes_Dataviz.new(root2)
]);
var data2 = [{
country: "USA",
visits: 3025
}, {
country: "China",
visits: 1882
}, {
country: "Japan",
visits: 1809
}, {
country: "Germany",
visits: 1322
}, {
country: "UK",
visits: 1122
}, {
country: "France",
visits: 1114
}, {
country: "India",
visits: 984
}];
// Create chart
var chart2 = root2.container.children.push(
am5xy.XYChart.new(root2, {
paddingBottom: 20
})
);
// Create axes
var xAxis2 = chart2.xAxes.push(
am5xy.CategoryAxis.new(root2, {
categoryField: "country",
renderer: am5xy.AxisRendererX.new(root2, {
minGridDistance: 10
})
})
);
xAxis2.get("renderer").labels.template.set("forceHidden", true);
xAxis2.data.setAll(data2);
var yAxis2 = chart2.yAxes.push(
am5xy.ValueAxis.new(root2, {
maxDeviation: 0.1,
renderer: am5xy.AxisRendererY.new(root2, {})
})
);
yAxis2.get("renderer").labels.template.set("forceHidden", true);
// Add series
var series2 = chart2.series.push(
am5xy.ColumnSeries.new(root2, {
minBulletDistance: 10,
xAxis: xAxis2,
yAxis: yAxis2,
valueYField: "visits",
categoryXField: "country"
})
);
series2.columns.template.setAll({
strokeOpacity: 0,
cornerRadiusTL: 10,
cornerRadiusTR: 10,
width: am5.percent(80)
});
series2.columns.template.adapters.add("fill", function(fill, target) {
return chart2.get("colors").getIndex(data2.indexOf(target.dataItem.dataContext));
});
series2.data.setAll(data2);
/**
* Chart 3
*/
// Create root element
var root3 = am5.Root.new("chartdiv3");
// Set themes
root3.setThemes([
am5themes_Animated.new(root3),
am5themes_Dataviz.new(root3)
]);
var data3 = [{
country: "USA",
year2004: 3.5,
year2005: 4.2
}, {
country: "UK",
year2004: 1.7,
year2005: 3.1
}, {
country: "Canada",
year2004: 2.8,
year2005: 2.9
}, {
country: "Japan",
year2004: 2.6,
year2005: 2.3
}, {
country: "France",
year2004: 1.4,
year2005: 2.1
}, {
country: "Brazil",
year2004: 2.6,
year2005: 4.9
}];
// Create chart
var chart3 = root3.container.children.push(
am5xy.XYChart.new(root3, {
paddingBottom: 20
})
);
// Create axes
var xAxis3 = chart3.xAxes.push(
am5xy.CategoryAxis.new(root3, {
categoryField: "country",
renderer: am5xy.AxisRendererX.new(root3, {
minGridDistance: 10
})
})
);
xAxis3.get("renderer").labels.template.set("forceHidden", true);
xAxis3.data.setAll(data3);
var yAxis3 = chart3.yAxes.push(
am5xy.ValueAxis.new(root3, {
maxDeviation: 0.1,
renderer: am5xy.AxisRendererY.new(root3, {})
})
);
yAxis3.get("renderer").labels.template.set("forceHidden", true);
// Add series
var series31 = chart3.series.push(
am5xy.ColumnSeries.new(root3, {
minBulletDistance: 10,
xAxis: xAxis3,
yAxis: yAxis3,
clustered: false,
valueYField: "year2004",
categoryXField: "country"
})
);
series31.columns.template.setAll({
strokeOpacity: 0,
cornerRadiusTL: 10,
cornerRadiusTR: 10,
width: am5.percent(80)
});
series31.data.setAll(data3);
var series32 = chart3.series.push(
am5xy.ColumnSeries.new(root3, {
minBulletDistance: 10,
xAxis: xAxis3,
yAxis: yAxis3,
clustered: false,
valueYField: "year2005",
categoryXField: "country"
})
);
series32.columns.template.setAll({
strokeOpacity: 0,
cornerRadiusTL: 6,
cornerRadiusTR: 6,
width: am5.percent(50)
});
series32.data.setAll(data3);
/**
* Chart 4
*/
// Create root and chart
var root4 = am5.Root.new("chartdiv4");
root4.setThemes([
am5themes_Animated.new(root4),
am5themes_Dataviz.new(root4)
]);
var chart4 = root4.container.children.push(
am5percent.PieChart.new(root4, {
paddingTop: 0,
paddingRight: 0,
paddingBottom: 0,
paddingLeft: 0
})
);
// Define data
var data4 = [{
country: "Lithuania",
value: 260
}, {
country: "Czechia",
value: 230
}, {
country: "Ireland",
value: 200
}, {
country: "Germany",
value: 165
}, {
country: "Australia",
value: 139
}, {
country: "Austria",
value: 128
}];
// Create series
var series4 = chart4.series.push(
am5percent.PieSeries.new(root4, {
name: "Series",
valueField: "value",
categoryField: "country"
})
);
series4.labels.template.set("forceHidden", true);
series4.ticks.template.set("forceHidden", true);
series4.slices.template.set("cornerRadius", 6);
series4.slices.template.adapters.add("radius", function (radius, target) {
var dataItem = target.dataItem;
var high = series4.getPrivate("valueHigh");
if (dataItem) {
var value = target.dataItem.get("valueWorking", 0);
return radius * value / high
}
return radius;
});
series4.data.setAll(data4);
src/input/style.css
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
.chart {
width: 100%;
height: 250px;
border: 1px solid #eee;
}
#chartdiv4 {
float: left;
margin: 0 20px 20px 0;
width: 30%;
}
.main {
max-width: 600px;
margin: 0 auto;
}
h2 {
margin-top: 2em;
clear: both;
}
br {
clear: both;
}
table {
width: 100%;
border: 1px solid #eee;
border-collapse: collapse;
}
table td, table th {
border: 1px solid #eee;
padding: 5px;
}
.col {
width: 50%;
float: left;
}
src/make_pdf_from_input.py
def make_pdf_from_input():
if __name__ == '__main__':
make_pdf_from_input()
Here I am completely stuck and need some guidance to where I should continue in order to combine the files into a PDF using Python.

pytest_schema fails to validate Enum

Given this json response:
api_schema = schema({
"sts": "OK",
"values": [
{
"mark": And(str, lambda s: len(s) > 1),
"desc": And(str, lambda s: len(s) > 1),
"observer": Enum(["testObs", "test"])
"created": And(int, lambda s: len(str(s)) >= 5),
}
]
})
rsp = {
"sts":"OK",
"values":[
{
"mark":"test",
"created":123213213,
"desc":"Ok",
"observer":"testObs",
}
]
}
print(api_schema.validate(data=rsp))
Raises:
schema.SchemaError: Key 'values' error:
Or({'mark': And(<class 'str'>, <function <lambda> at 0x0000010A9B6A04A0>), 'desc': And(<class 'str'>, <function <lambda> at 0x0000010A9B858E00>), 'observer': Enum(['testObs', 'BY_CARRIER', 'BY_ALL_DEVICES', 'BY_ALL_USERS', 'BY_USER_ID', 'BY_DEVICE_ID']), 'created': And(<class 'int'>, <function <lambda> at 0x0000010A9B859C60>)}) did not validate {'mark': 'test', 'created': 123213213, 'desc': 'Ok', 'observer': 'testObs'}
Key 'observer' error:
Enum(['testObs', 'BY_CARRIER', 'BY_ALL_DEVICES', 'BY_ALL_USERS', 'BY_USER_ID', 'BY_DEVICE_ID']) did not validate 'testObs'
'testObs' should be instance of 'list'
But it dosent make sense "testObs" is indeed part of "observer": Enum(["testObs"...
Lorem ipsum so i can post:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
It seems as if the "Full example" in their Readme is outdated. This PR shows that instead of passing your Enum values as a list, you should pass them as arguments:
"observer": Enum("testObs", "test"),
Putting it back in your example it now works as expected:
from pytest_schema import schema, Enum, And, Regex, Optional, Or
api_schema = schema({
"sts": "OK",
"values": [
{
"mark": And(str, lambda s: len(s) > 1),
"desc": And(str, lambda s: len(s) > 1),
"observer": Enum("testObs", "test"),
"created": And(int, lambda s: len(str(s)) >= 5),
}
]
})
rsp = {
"sts":"OK",
"values":[
{
"mark":"test",
"created":123213213,
"desc":"Ok",
"observer":"testObs",
}
]
}
print(api_schema.validate(data=rsp))
=>
āÆ python python_test.py
{'sts': 'OK', 'values': [{'mark': 'test', 'created': 123213213, 'desc': 'Ok', 'observer': 'testObs'}]}

Dash : how change color of dropdown menu backround and text

I have Dash app and I am trying to change the color of my dropdown list to have a black background and white text in "Bold arial".
Here is the part of code with the dropdown parameters :
dcc.Dropdown(
id='langue_dropdown',
options=[{'label': i, 'value': i}
for i in langues],
value='fr',
placeholder="langue"),
style={'font-family': 'arial', "font-size": "1.2em",
'marginBottom': 10, 'marginTop': 2, 'text-align': 'center'})
When I change my code to get a black backround, code :
dcc.Dropdown(
id='langue_dropdown',
options=[{'label': i, 'value': i}
for i in langues],
value='fr',
placeholder="langue"),
style={'font-family': 'arial', "font-size": "1.2em",
'marginBottom': 10, 'marginTop': 2, 'text-align': 'center',"background-color":"#151515", "color": "white"})
I don't get the expected result, the backround of list menu not change to black ?
Iā€™m new to Dash and plotly and donā€™t have much experience with css stylesheets, so please let me know if there is basic information that I havenā€™t provided.
Thanks.
You can do this by adding a style.css file in your assets folder with the following classes:
.Select-control {
background-color: rgb(25, 25, 25) !important;
color:white;
}
.Select-menu-outer {
background-color: rgb(25, 25, 25);
color: white;
}
.Select-value-label {
color: white !important;
}
The above classes will change all the dropdowns in your application, but if you want to do something special that will be to a specific dropdown/element, you can use the id to specify in what element you need to apply your CSS class.
Below is a second example with the same classes I provided above, but with the id in the start of the class:
#langue_dropdown .Select-control {
background-color: red !important;
color:white;
}
#langue_dropdown .Select-menu-outer {
background-color: rgb(25, 25, 25);
color: white;
}
/* changes the text color of input box */
#langue_dropdown .Select-value-label {
color: rgb(37, 224, 37) !important;
}
Below is a working example showing how it works in practice:
from dash import Dash, dcc, html, Input, Output
app = Dash(__name__)
app.layout = html.Div([
dcc.Dropdown(
id='langue_dropdown',
options=[{'label': i, 'value': i}
for i in ["en", "pt", "fr","jp"]],
value='fr',
placeholder="langue"),
dcc.Dropdown(
id='langue_dropdown2',
options=[{'label': i, 'value': i}
for i in ["en", "pt", "fr","jp"]],
value='fr',
placeholder="langue"),
html.Div(id='dd-output-container')
])
#app.callback(
Output('dd-output-container', 'children'),
Input('langue_dropdown', 'value')
)
def update_output(value):
return f'You have selected {value}'
if __name__ == '__main__':
app.run_server(debug=True)
and in CSS file assets/style.css
.Select-control {
background-color: rgb(25, 25, 25) !important;
color:white;
}
.Select-value-label {
color: white !important;
}
.Select-menu-outer {
background-color: rgb(25, 25, 25);
color: white;
}
#langue_dropdown .Select-value-label {
color: rgb(37, 224, 37) !important;
}
#langue_dropdown .Select-control {
background-color: red !important;
color:white;
}
#langue_dropdown .Select-menu-outer {
background-color: rgb(25, 25, 25);
color: white;
}
If it solves your problem, please set it as the correct answer!
Otherwise, let me know if something is not clear yet.
Regards,
Leonardo

ValueError: Expected object or value while reading JSON using Pandas with Chunksize and lines=True

I've looked into mutliple stackoverflow threads and pandas document but I am still getting following error when trying to read json as below
source: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#io-json-reader and section Line delimited json
import pandas as pd
chunks = pd.read_json('/Users/abc/PycharmProjects/test-json/records1.json', lines=True, chunksize=10)
for chunk in chunks:
print(chunk)
break
error
Traceback (most recent call last):
File "/Users/abc/PycharmProjects/abc_code/test.py", line 4, in <module>
for chunk in chunks:
File "/Users/abc/.local/share/virtualenvs/abc_code-bU7zXpdS/lib/python3.8/site-packages/pandas/io/json/_json.py", line 744, in __next__
obj = self._get_object_parser(lines_json)
File "/Users/abc/.local/share/virtualenvs/abc_code-bU7zXpdS/lib/python3.8/site-packages/pandas/io/json/_json.py", line 716, in _get_object_parser
obj = FrameParser(json, **kwargs).parse()
File "/Users/abc/.local/share/virtualenvs/abc_code-bU7zXpdS/lib/python3.8/site-packages/pandas/io/json/_json.py", line 831, in parse
self._parse_no_numpy()
File "/Users/abc/.local/share/virtualenvs/abc_code-bU7zXpdS/lib/python3.8/site-packages/pandas/io/json/_json.py", line 1079, in _parse_no_numpy
loads(json, precise_float=self.precise_float), dtype=None
**ValueError: Expected object or value**
PS:
It works fine if I read without lines=True, chunksize=10 params but isn't working with these params. reason I am using these params is because we get big jsons and I don't want to load all of that in memory in single go.
For testing purpose, let's say I want to filter people from this json for whom "isActive": true.
I am using python v3.7.9 and pandas v1.3.1
thanks for the help!!
For reference, please find below the sample snippet of json which I am trying to read
[{
"_id": "5c21a63a1e4bb8d6a7d1ffa0",
"index": 0,
"guid": "ae4d6f3d-ad3f-4923-8b87-8456d427f96e",
"isActive": true,
"balance": "$3,624.10",
"picture": "http://placehold.it/32x32",
"age": 30,
"eyeColor": "blue",
"name": {
"first": "Alvarado",
"last": "Castro"
},
"company": "ARTWORLDS",
"email": "alvarado.castro#artworlds.com",
"phone": "+1 (937) 418-3892",
"address": "190 Joralemon Street, Talpa, Hawaii, 4597",
"about": "Veniam ut officia exercitation eiusmod officia nulla id est consectetur. Laboris excepteur id dolore consequat dolore ad deserunt anim anim. Eu ea ad cupidatat consequat duis id ut elit adipisicing ea minim irure ullamco voluptate. Irure reprehenderit duis esse esse dolore voluptate ad. Reprehenderit veniam qui velit cupidatat. Veniam consectetur aliquip quis sit laboris sint adipisicing occaecat occaecat consequat sint.",
"registered": "Friday, October 5, 2018 6:26 PM",
"latitude": "-59.473097",
"longitude": "118.295711",
"tags": [
"adipisicing",
"incididunt",
"deserunt",
"commodo",
"nisi"
],
"range": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
],
"friends": [{
"id": 0,
"name": "Mcgee Delacruz"
},
{
"id": 1,
"name": "Marquita Robinson"
},
{
"id": 2,
"name": "Mullen Foreman"
}
],
"greeting": "Hello, Alvarado! You have 7 unread messages.",
"favoriteFruit": "banana"
}]

Categories

Resources