Automate your reporting with
Quarto Dashboards and
Posit Connect
Agenda
Today’s project
What is Quarto?
Quarto dashboards
Publishing on Posit Connect
Demo
The Consumer Price Index (CPI), released monthly by the Bureau of Labor Statistics (BLS) in the United States
Agenda
Today’s project
What is Quarto?
Quarto dashboards
Publishing on Posit Connect
Demo
Quarto® is an
open-source
scientific and technical
publishing system
built on Pandoc.
A tool for weaving together narrative and code to produce elegantly formatted outputs.
---
title: "Palmer Penguins Demo"
format: html
jupyter: python3
---
## Meet Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
```{python}
#| echo: false
#| message: false
import pandas as pd
import seaborn as sns
from palmerpenguins import load_penguins
sns.set_style('whitegrid')
penguins = load_penguins()
g = sns.lmplot(x="flipper_length_mm",
y="body_mass_g",
hue="species",
height=7,
data=penguins,
palette=['#FF8C00','#159090','#A034F0']);
g.set_xlabels('Flipper Length');
g.set_ylabels('Body Mass');
```
---
title: "Palmer Penguins Demo"
format: revealjs
jupyter: python3
---
## Meet Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
```{python}
#| echo: false
#| message: false
import pandas as pd
import seaborn as sns
from palmerpenguins import load_penguins
sns.set_style('whitegrid')
penguins = load_penguins()
g = sns.lmplot(x="flipper_length_mm",
y="body_mass_g",
hue="species",
height=7,
data=penguins,
palette=['#FF8C00','#159090','#A034F0']);
g.set_xlabels('Flipper Length');
g.set_ylabels('Body Mass');
```
Agenda
Today’s project
What is Quarto?
Quarto dashboards
Publishing on Posit Connect
Demo
A new output format for easily creating dashboards from notebooks
---
title: "Development Indicators by Continent"
author: "Gapminder Analytics Group"
format: dashboard
---
```{python}
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"
)
```
Navigation bar and pages – Icon, title, and author along with links to sub-pages (if more than one page is defined)
Pages, rows, columns, and tabsets — Pages, rows and columns are defined using markdown headings
Cards, sidebars, and toolbars – Display information and inputs
Note
Register for the Quarto Dashboards workshop at posit::conf(2024), August 12 in Seattle! https://pos.it/conf
```{python}
#| title: "World Map"
#| padding: 0px
from ipyleaflet import Map, basemaps, basemap_to_tiles
Map(basemap=basemap_to_tiles(basemaps.OpenStreetMap.Mapnik),
center=(48.204793, 350.121558), zoom=2)
```
Quarto includes 25 themes from the Bootswatch project:
Quarto allows for extensive customization of themes using Sass:
title: "Stock Explorer"
author: "Ty Coon"
logo: logo.png
format:
dashboard:
theme: [yeti, custom.scss]
---
title: 'Inflation explorer: showing the change in price for various goods and services'
format:
dashboard:
logo: images/logo.png
nav-buttons:
- icon: github
href: https://github.com/posit-marketing
---
```{python}
#| include: false
import markdown
import pins
from pins import board_connect
import pandas as pd
import plotly.express as px
import plotly.io as pio
import altair as alt
from dotenv import load_dotenv
load_dotenv()
import os
from plotnine import ggplot, aes, geom_bar, scale_fill_manual, labs, theme_minimal, theme, element_text
from IPython.display import display, Markdown, Latex
connect_server = connect_server = os.environ.get('CONNECT_SERVER')
connect_api_key = os.environ.get('CONNECT_API_KEY')
board = board_connect(server_url=connect_server, api_key=connect_api_key)
df = board.pin_read('isabella.velasquez/bls-cpi-data')
pio.templates.default = 'plotly_white'
# Value for last updated date
df['Year-Month'] = pd.to_datetime(df['Year-Month'])
last_updated_date = df['Year-Month'].max().strftime('%B %Y')
cpi_df = df[df['Category'] == 'CUUR0000SA0']
latest_cpi_value = cpi_df['value'].iloc[-1]
latest_cpi_percent_change = cpi_df['Percent_Change_from_Previous_Month'].iloc[-1]
```
## Row {height=20%}
```{python}
#| content: valuebox
#| title: 'Last updated'
#| color: #fff
last_updated_date
```
```{python}
#| content: valuebox
#| title: 'Consumer Price Index (CPI)'
#| icon: basket
#| color: primary
dict(
value = latest_cpi_value.round(2)
)
```
```{python}
#| content: valuebox
#| title: 'Increase from previous month'
#| icon: percent
#| color: primary
dict(
value = latest_cpi_percent_change.round(2)
)
```
## Row {height=80%}
### Column {width=20%}
The **Consumer Price Index (CPI)** is a measure of the average change over time in the prices paid by urban consumers for a market basket of consumer goods and services.
Indexes are available for the U.S. and various geographic areas. Average price data for select utility, automotive fuel, and food items are also available.
Source:
Bureau of Labor Statistics
### Column {.tabset width=80%}
```{python}
#| label: pct-change-jan-2018-code
#| include: false
df = df.sort_values(by=['Category_Label', 'Year-Month'], ascending=[False, False])
fig = px.line(df, x='Year-Month', y='Percent_Change_from_January_2018', color='Category_Label', hover_name='Category_Label')
for d in fig['data']:
if d['name'] == 'All groups CPI':
d['line']['color'] = 'orange'
d['legendgroup'] = 1
else:
d['line']['color'] = 'lightgrey'
fig.update_xaxes(title_text='')
fig.update_yaxes(title_text='')
```
```{python}
#| label: pct-change-jan-2018-plot
#| title: 'Percentage change since Jan 2018'
display(Markdown('Use this inflation data explorer to see which goods and services are getting cheaper or more expensive in the U.S.'))
fig.show()
```
```{python}
#| label: pct-change-monthly-code
#| include: false
latest_month_data = df[df['Year-Month'] == df['Year-Month'].max()]
latest_month_data_sorted = latest_month_data.sort_values(by='Percent_Change_from_Previous_Month', ascending=False)
top_six_categories = latest_month_data_sorted.head(6)
fig = px.bar(top_six_categories, x='Category_Label', y='Percent_Change_from_Previous_Month',
title='',
color='Category_Label',
color_discrete_sequence=px.colors.sequential.Reds[::-1])
fig.update_layout(xaxis_title='', yaxis_title='Percent Change',
yaxis_tickformat='%.1f%%')
```
```{python}
#| label: pct-change-monthly-plot
#| title: "Last month's top 6"
display(Markdown('Percentage change in CPI by category for the latest month, top six categories'))
fig.show()
```
```{python}
#| title: 'Monthly percentage change'
display(Markdown('Use this inflation data explorer to see which goods and services are getting cheaper or more expensive in the U.S.'))
```
Agenda
Today’s project
What is Quarto?
Quarto dashboards
Publishing on Posit Connect
Demo
Posit Connect is a publishing platform that makes the delivery of data science content fast, approachable, and secure.
Posit Connect accepts publishing Shiny, Dash, Streamlit, Bokeh, R Markdown, Jupyter Notebook, FastAPI, Flask, Plumber…
and Quarto documents!
rsconnect deploy
command deploys content to Posit ConnectReports that are published with source code can be re-executed by Posit Connect.
Emails can delivered after re-execution to
Agenda
Today’s project
What is Quarto?
Quarto dashboards
Publishing on Posit Connect
Demo
https://github.com/posit-marketing/inflation-explorer