My primary interest here is the dashboard functionality and construction. This example taken was reproduced from the Quarto website which is in turn takes the data from the Python plotly.data package. The call to gapminder() returns a pandas.DataFrame with data from GapMinder. Simple function calls to plotly.express scatter(), area() and line() populate the dashboard. This functionality is possible with just five lines of code! (OK, if the code were poorly formatted. Better to say, 4 function calls and a library import). The code can be seen in the “Code” tab. In any case, it’s impressive how much functionality is available “off the shelf”.
---
title: "Example #1"
format: dashboard
---
# Dashboard
My primary interest here is the dashboard functionality and construction. This example taken was reproduced from the [Quarto
website](https://quarto.org/docs/dashboards/ "Quarto website") which is in turn takes the data from the [Python plotly.data
package](https://plotly.com/python-api-reference/generated/plotly.data.html#module-plotly.data "Python plotly.data package"). The
call to gapminder() returns a pandas.DataFrame with data from [GapMinder](https://www.gapminder.org/data/ "GapMinder"). Simple
function calls to [plotly.express](https://plotly.com/python-api-reference/plotly.express.html "plotly.express") scatter(), area()
and line() populate the dashboard. This functionality is possible with just five lines of code! (OK, if the code were poorly
formatted. Better to say, 4 function calls and a library import). The code can be seen in the "Code" tab. In any case, it's
impressive how much functionality is available "off the shelf".
```{python}
# comments
import plotly.express as px
df = px.data.gapminder()
```
## Row {height="60%"}
```{python}
#| title: GDP and Life Expectancy
px.scatter(
df, x="gdpPercap", y="lifeExp",
animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
facet_col="continent", log_x=True, size_max=45,
range_x=[100,100000], range_y=[25,90]
)
```
## Row {height="40%"}
```{python}
#| title: Population
px.area(
df, x="year", y="pop",
color="continent", line_group="country"
)
```
```{python}
#| title: Life Expectancy
px.line(
df, x="year", y="lifeExp",
color="continent", line_group="country"
)
```
# Code
## Row
```{python}
from pathlib import Path
from textwrap import wrap
# wrap just the long lines over a specified number of characters
def wrap_long_lines(input_text, max_line_chars):
lines = input_text.split('\n')
wrapped_lines = []
for line in lines:
if len(line) > max_line_chars:
wrapped_lines.extend(wrap(line, width=max_line_chars))
else:
wrapped_lines.append(line)
wrapped_text = '\n'.join(wrapped_lines)
return wrapped_text
txt = Path('example_1.qmd').read_text()
# its a wrap!
# those long comments are now readable the Code tab
wrapped_txt = wrap_long_lines(txt, 130)
print(wrapped_txt)
```