You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_quarto.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ quartodoc:
37
37
38
38
sections:
39
39
- title: Power Bpy
40
-
desc: The first thing you should create is an instance of the Dashboard class. Then use the `add_page()` or `load_page()` functions to attach instances of the internal `_Page` class. All methods are attached to either dashboards or pages. Click below to see which methods are attached to which. For more details about how to build dashboards, see the test dashboard [tutorial](https://www.russellshean.com/powerbpy/example_dashboards/Test%20Dashboard/Testing%20Dashboard.html) section of this website.
40
+
desc: The first thing you should create is an instance of the Dashboard class. Then use the `add_page()` or `load_page()` functions to attach instances of the internal `_Page` class to the Dashboard. All methods are attached to either dashboards or pages. Click below to see which methods are attached to which. For more details about how to build dashboards, see the test dashboard [tutorial](https://www.russellshean.com/powerbpy/example_dashboards/Test%20Dashboard/Testing%20Dashboard.html) section of this website.
41
41
contents:
42
42
# the functions being documented in the package.
43
43
# you can refer to anything: class methods, modules, etc..
1. Make sure [python](https://www.python.org/downloads/) is installed on your computer.
6
+
# Setup
7
+
This document briefly covers how to setup your python environment so you can start using the package to build dashboard. If anything doesn't make sense, please open a pull request or issue so I can improve this documentation. While you're waiting for me to fix the doccumentation, there are numerous other tutorials online that explain how to install python, create virtual environments and run python scripts.
8
+
9
+
## Python
10
+
11
+
1. Make sure [python](https://www.python.org/downloads/) is installed on your computer.
12
+
13
+
## Create virtual environment
14
+
For this example, we're going to use a virtual environment to keep the package versions separate from what you have installed on your system
9
15
10
-
## Create virtual environment
11
-
For this example, we're going to use a virtual environment to keep the package versions separate from what you have installed on your system
12
-
1. Open a command prompt and navigate to the folder you want to create dashboards in by running the following:
16
+
1. Open a command prompt and navigate to the folder you want to create dashboards in by running the following:
13
17
```shell
14
18
cd path/to/your/folder
15
19
```
16
-
2. Create and activate a virtual environment by running the same:
20
+
21
+
2. Create and activate a virtual environment by running the same:
17
22
```shell
18
23
# create a virtual environment
19
24
python -m venv venv
@@ -25,46 +30,21 @@ For this example, we're going to use a virtual environment to keep the package v
25
30
# source venv/bin/activate
26
31
```
27
32
28
-
2. Install the Power Bpy module:
33
+
2. Install the Power Bpy module:
29
34
```shell
30
35
# install the Power Bpy module
31
36
pip install powerbpy
32
-
```
37
+
```
38
+
3. Write a script to create a dashboard. (This one's up to you!)
33
39
34
-
3. Write a script to create a dashboard. (This one's up to you!)
35
-
36
-
4. When you're ready to create the dashboard, run the script by running the following in the command prompt window.
37
-
38
-
```shell
39
-
python name_of_your_script.py
40
-
```
40
+
4. When you're ready to create the dashboard, run the script by running the following in the command prompt window. ```shell
41
+
python name_of_your_script.py
42
+
```
41
43
42
44
43
-
## Install dependencies
44
-
1. Install python
45
-
You'll need to install python. Here are some <ahref="https://www.geeksforgeeks.org/download-and-install-python-3-latest-version/">instructions</a>
46
-
2. Install Power Bpy
47
-
The `{powerbpy}` package isn't on pypi yet, so you'll need to install it from github. <ahref="https://www.lifewire.com/how-to-open-command-prompt-2618089">Open a terminal</a> and enter the following:
48
-
45
+
## Development version
46
+
To install the latest version of Power Bpy from Github instead of Pypi you can run the following
After the package is on pypi, you'll be able to install it using this:
54
-
```batchfile
55
-
py -m pip install powerbpy
56
-
```
57
-
58
-
## Executing python scripts
59
-
That's all you need to install! To create the dashboards, you'll need to either run the commands in a terminal, or use a text editor to save the commands in a a script. I recomend starting with a text editor, because as your dashboard grows more complex, it'll be helpful to have everything saved in a script. Many text editors have an option to execute a script directly from the editor. You can also execute the scripts from the terminal using the following command:
60
-
```dosbat
61
-
py build_dashboard.py
62
-
```
63
-
This assumes that you named your script `build_dashboard.py` and the command prompt's current directory is the folder storing `build_dashboard.py`. You can change the current directory of the terminal using the `cd` command. For example you can use the following to move into `C:/Users/`:
64
-
```dosbat
65
-
cd C:/Users/
66
-
```
67
-
You can also use full or relative paths from the current directory to the python script without changing the current working directory. For example if you start in your `%userprofile%` (`C:/Users/[your username]`) and the python script is stored at `C:/Users/[your username]/python_projects/build_dashboard.py`, you can execute the script with the following:
I used the PowerBpy python module to recreate an <ahref="https://workout-wednesday.com/pbi-2025-w13/">sanky chart and table</a> dashboard from the <ahref="https://workout-wednesday.com/">Workout Wednesday Group</a> challenge. Here's a screenshot of the original dashboard (top) and the dashboard I recreated using Power Bpy (bottom). (It appears that the data has changed since the original author created his dashboard, so my version and his look a bit different because the data is a bit different, but the overall format is pretty similiar). The rest of the blog will describe key parts of the code I used to make the dashboard. The full code is available [here](https://github.com/Russell-Shean/powerbpy-demos/tree/main/WOW/2025/13).
Copy file name to clipboardExpand all lines: docs/example_dashboards/Test Dashboard/Testing Dashboard.qmd
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ This example shows how I create the dashboard I use for testing the module. It i
18
18
19
19
20
20
# Setup
21
-
If you don't already have python and the `{powerbpy}` module installed, please refer to the setup instructions first.
21
+
If you don't already have python and the `{powerbpy}` module installed, please refer to the setup [instructions](https://www.russellshean.com/powerbpy/basic_setup.html) first.
In addition to visuals, many dashboards use explanatory text. Here's an example of adding a text box to a page. The following arguments are required:
139
139
140
140
1.`text` - The text you want to display in the box
@@ -214,7 +214,11 @@ Often we have data that is tied to geographic regions that can be respresented b
214
214
215
215
This function does a lot under the hood so you don't have to. It creates measures in the dataset so that bins will automatically adjust when filtering conditions change, it creates the map and adds text boxes for a legend and and a slicer to allow the user to filter the data. The method requires you to provide a shape file that corresponds to a variable in your dataset. For example, the dataset could have two columns: US states and average income. In this case you should provide a shapefile of US states.
216
216
217
-
The method also give two different options for binning the data and assigning ranges of values to different colors on the map. You can only specify one of the two options at a time. The first option is to provide a static set of breaks that you define yourself. This is ideal if you already know the structure of your data and how you want to assign ranges of values to different colors. Use the `static_bin_breaks` argument to pass an integer list of break values. The second option is to provide a list of percentiles that you want to use to bin the data into ranges. This option is intended to be used in conjunction with a third variable that you use to filter the data. For example, assume you have a third variable in your dataset of average income by state dataset, maybe age. You could pass age to the `filtering_var` argument to create a slicer attached to the map that filters the dataset by age before rerendering the map. You could then pass the list of percentiles to `percentile_bin_breaks` such as 0, 0.2, 0.4, 0.6, 0.8, 1. This will create breaks between 0% and 20%, 20% and 40%, etc and the bins will be recalculated each time the slicer filters are adjusted. So, for this example, if you selected "young people" in the slicer, the bins will be re-calculated and the map will re-render to show 20, 40, 60 etc, percentiles for just young people. If you provide `percentile_bin_breaks` you must also provide a `filtering_var`; the assumption being that if you don't need dynamic recalculation of bins based on the filtering variable, you'd be better off calculating a static set of breaks for yourself and passing them as a list to `static_bin_breaks`.
217
+
The method also give two different options for binning the data and assigning ranges of values to different colors on the map. You can only specify one of the two options at a time.
218
+
219
+
The first option is to provide a static set of breaks that you define yourself. This is ideal if you already know the structure of your data and how you want to assign ranges of values to different colors. Use the `static_bin_breaks` argument to pass an integer list of break values.
220
+
221
+
The second option is to provide a list of percentiles that you want to use to bin the data into ranges. This option is intended to be used in conjunction with a third variable that you use to filter the data. For example, assume you have a third variable in your dataset of average income by state dataset, maybe age. You could pass age to the `filtering_var` argument to create a slicer attached to the map that filters the dataset by age before rerendering the map. You could then pass the list of percentiles to `percentile_bin_breaks` such as 0, 0.2, 0.4, 0.6, 0.8, 1. This will create breaks between 0% and 20%, 20% and 40%, etc and the bins will be recalculated each time the slicer filters are adjusted. So, for this example, if you selected "young people" in the slicer, the bins will be re-calculated and the map will re-render to show 20, 40, 60 etc, percentiles for just young people. If you provide `percentile_bin_breaks` you must also provide a `filtering_var`; the assumption being that if you don't need dynamic recalculation of bins based on the filtering variable, you'd be better off calculating a static set of breaks for yourself and passing them as a list to `static_bin_breaks`.
218
222
219
223
I'll describe in more detail below some of the optional method arguments and how they can be used to customize your map. But first, here are the required arguments:
220
224
@@ -224,10 +228,7 @@ I'll describe in more detail below some of the optional method arguments and how
224
228
4.`map_title` - The title you want to put above the map.
225
229
5.`location_var` - The name of the column in data_source that you want to use for the location variable on the map. This should also correspond to the geography of your shape file.
226
230
6. color_var: The name of the column in data_source that you want to use for the color variable on the map. This variable should be numeric.
227
-
filtering_var: str
228
-
Optional. The name of a column in data source that you want to use to filter the color variable on the map. This must be supplied if providing percentile_bin_breaks. If you want to use percentiles without filtering (ie on static data), you should calculate the percentiles yourself and pass them to static_bin_breaks. Do not provide both static_bin_breaks and a filtering_var.
229
-
static_bin_breaks: list
230
-
This should be a list of numbers that you want to use to create bins in your data. There should be one more entry in the list than the number of bins you want and therefore the number of colors passed to the color_palette argument. The function will create bins between the first and second number, second and third, third and fourth, etc. A filtering_var cannot be provided if static_bin_breaks is provided. Use percentile bin breaks instead.
231
+
231
232
color_palatte: list
232
233
A list of hex codes to use to color your data. There should be one fewer than the number of entries in static_bin_breaks
Copy file name to clipboardExpand all lines: src/powerbpy/page.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
class_Page:
10
10
'''A python class used to model a power BI dashboard page.
11
11
12
-
You should never initate a page class directly, instead use Dashboard.new_page() to create a new page, or Dashboard.load_page() to load an existing page. This class is important however because its methods are public. The reason you should never create an instance of the _Page class directly is simple -- it doesn't make sense to have a page not attached to a dashboard.
12
+
You should never initate a page class directly, instead use `Dashboard.new_page()` to create a new page, or `Dashboard.load_page()` to load an existing page. This class is important however because its methods are public. The reason you should never create an instance of the _Page class directly is simple -- it doesn't make sense to have a page not attached to a dashboard.
13
13
14
14
Here's an example workflow:
15
15
```python
@@ -566,7 +566,7 @@ def add_shape_map(self,
566
566
static_bin_breaks: list
567
567
This should be a list of numbers that you want to use to create bins in your data. There should be one more entry in the list than the number of bins you want and therefore the number of colors passed to the color_palette argument. The function will create bins between the first and second number, second and third, third and fourth, etc. A filtering_var cannot be provided if static_bin_breaks is provided. Use percentile bin breaks instead.
568
568
color_palette: list
569
-
A list of hex codes to use to color your data. There should be one fewer than the number of entries in static_bin_breaks
569
+
A list of hex codes to use to color your data. There should be one fewer than the number of bins.
570
570
add_legend: bool
571
571
True or False, would you like to add the default legend? (By default legend, I mean this function's default, not the Power BI default)
Copy file name to clipboardExpand all lines: src/powerbpy/shape_map.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ def __init__(self,
65
65
static_bin_breaks: list
66
66
This should be a list of numbers that you want to use to create bins in your data. There should be one more entry in the list than the number of bins you want and therefore the number of colors passed to the color_palette argument. The function will create bins between the first and second number, second and third, third and fourth, etc. A filtering_var cannot be provided if static_bin_breaks is provided. Use percentile bin breaks instead.
67
67
color_palatte: list
68
-
A list of hex codes to use to color your data. There should be one fewer than the number of entries in static_bin_breaks
68
+
A list of hex codes to use to color your data. There should be one fewer than the number of bins.
69
69
add_legend: bool
70
70
True or False, would you like to add the default legend? (By default legend, I mean this function's default, not the Power BI default)
0 commit comments