Skip to content

Commit cccad11

Browse files
authored
Merge branch 'master' into chore/update_lcobucci/jwt
2 parents b2fee37 + 8478c5f commit cccad11

File tree

22 files changed

+6048
-4813
lines changed

22 files changed

+6048
-4813
lines changed

README.md

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,87 @@
1-
# embedding-reference-apps
2-
Reference applications for common web frameworks showing how to embed Metabase charts
1+
# Embedding Metabase dashboards: reference web apps
32

4-
# Running the apps
5-
1. Run the metabase server with `java -jar metabase.jar` from the `/metabase` directory
6-
2. Run the relevant reference application
3+
This repo contains example applications for common web frameworks to demonstrate how [Metabase](https://www.metabase.com/) dashboards can be embedded in your application.
74

8-
For the Django application
9-
`./manage.py runserver`
5+
This README will walk you through getting Metabase up and running, as well as a simple web app, to show you a live example of an embedded dashboard.
106

11-
For the Node application
12-
`node index.js`
7+
Here's a simple Metabase dashboard in action:
138

14-
For the rails application
15-
`rails server -p 3001`
16-
(Note that we're binding to a nonstandard port as Metabase also runs on 3000)
9+
![Simple Metabase dashboard embedded in Node application](/static/img/metabase_node_embed.gif)
1710

18-
# Helpful info
19-
Admin login is
20-
user: plucky@admin.com
21-
password: Metabase123
11+
## Premium embedding
12+
13+
Embedding Metabase charts will always be free, but we include a "Powered by Metabase" graphic when using the open source version.
14+
15+
If you'd like to remove the "Powered by Metabase" attribution, check out our [Enterprise Edition](https://www.metabase.com/enterprise/) which lets you do so so as well as white-label the application.
16+
17+
## Prerequisites
18+
19+
- Java version 8.x or 11.x. [Install OpenJDK](https://openjdk.java.net/install/).
20+
21+
## Set up Metabase
22+
23+
We'll first need to set up a running instance of Metabase to serve the embedded dashboards.
24+
25+
1. If you already have an instance of Metabase running on your machine, shut it down.
26+
27+
2. Open up a terminal and clone this repo to your machine.
28+
29+
3. `cd` into embedding-reference-apps.
30+
31+
3. Run the the prepare script.
32+
33+
```shell
34+
./prepare.sh
35+
```
36+
37+
The prepare.sh script downloads the latest version of Metabase to this repository's [metabase](/metabase) directory, changes into that directory, and runs the jar:`java -jar metabase.jar`.
38+
39+
Metabase will log its progress in the terminal as the jar runs. Once you see the line, "Metabase Inititalization COMPLETE", open your browser to [localhost:3000](http://localhost:3000) to see that Metabase is up and running.
40+
41+
## Running the apps
42+
43+
To see an embedded Metabase dashboard in action, [set up Metabase](#set-up-metabase), and follow the instructions in the README for the relevant app. If you're not sure which one to try, check out the [Node app](/node/README.md).
44+
45+
- [Node](/node/README.md)
46+
47+
- [Django](/django/embedded-analytics/README.md)
48+
49+
- [Rails](/rails/embedded-analytics/README.md)
50+
51+
- [Laravel](/laravel/embedded-analytics/README.md)
52+
53+
## Embedding charts or dashboards
54+
55+
There are two ways to embed charts or dashboards in web applications:
56+
57+
### Public embeds
58+
59+
The Public embedding method is to simply use the public URLs inside of an iframe, or really anywhere you can insert HTML. The embedded dashboard has a secure URL, so a user can only look at the contents of the dashboard being shared. An end user never has information they can use to modify the URL and gain access to any other resources on your Metabase instance.
60+
61+
### Signed embeds
62+
63+
With signed embedding, all embedded charts and dashboards have to be signed using a secret key. This allows you to build dynamic dashboards with a parameter that can be be locked down on the client side. You should sign embedded charts and dashboards on your server, which allows you to embed dashboards accessible to specific organizations, accounts, or users.
64+
65+
The web applications go into more detail about embedding, and provide examples. Start up the [Node app](/node/README.md) and explore the app.
66+
67+
## Documentation on embeds
68+
69+
You can also learn more about embedding dashboards by reading [Metabase's documentation](https://www.metabase.com/docs/latest/).
70+
71+
- [Quick search: embed](https://www.metabase.com/search.html?query=embed).
72+
73+
Article links:
74+
75+
- [Embedding Metabase components in other applications](https://www.metabase.com/docs/latest/administration-guide/13-embedding.html)
76+
- [Embedding all of Metabase in your web app](https://www.metabase.com/docs/latest/enterprise-guide/full-app-embedding.html)
77+
- [Sharing and embedding dashboards or questions](https://www.metabase.com/docs/latest/administration-guide/12-public-links.html)
78+
79+
## Helpful info
80+
Credentials for Metabase should auto-populate, but here they are for reference:
81+
82+
- user: plucky@admin.com
83+
- password: Metabase123
84+
85+
## Run into trouble?
86+
87+
Check out the [Metabase discussion forum](https://discourse.metabase.com/) and search for your issue. If you don't find any answers, please [create an issue](https://github.com/metabase/embedding-reference-apps/issues/new/choose) for this repository.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Django app
2+
3+
This Django application demonstrates a simple, barebones Metabase dashboard embedded in a web application.
4+
5+
## Prerequisites
6+
7+
- **Metabase**. You should have already completed the setup detailed in the [README](../../README.md) for this repository, which shows you how to get an instance of Metabase up and running in the [metabase](../../metabase) directory of this repository.
8+
9+
- **Python**. You'll need to have [Python](https://www.python.org/) installed on your machine.
10+
11+
## Set up the Django application
12+
13+
1. In a new terminal session, `cd` into [/embedded-analytics](/embedded-analytics).
14+
15+
2. Install the application's dependencies:
16+
17+
```shell
18+
pip install -r requirements.txt
19+
```
20+
21+
3. Once the dependencies are installed, start the application by running:
22+
23+
```shell
24+
./manage.py runserver
25+
```
26+
27+
4. Open your browser to [localhost:8000](http://localhost:8000).
28+
29+
Explore the app to learn more about embedding Metabase charts and dashboards in applications. You can also check out the links to more documentation in the parent repository's main [README](../../README.md).
30+
31+
## Example embedding code
32+
33+
You can find example code for embedding Metabase in [user_stats/views.py](user_stats/views.py).
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Django==1.10.5
1+
Django==1.11.28
22
django-allauth==0.30.0
33
PyJWT==1.4.2

django/embedded_analytics/user_stats/templates/user_stats/signed_chart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1>Embedding charts with signed parameters</h1>
2323
}
2424
}
2525

26-
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
26+
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
2727

2828
iframeUrl = METABASE_SITE_URL + "/embed/question/" + token + "#bordered=true"
2929
</pre>

django/embedded_analytics/user_stats/templates/user_stats/signed_dashboard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h1>Embedding dashboards with signed parameters</h1>
2727
}
2828
}
2929

30-
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
30+
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
3131

3232
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
3333
</pre>

django/embedded_analytics/user_stats/templates/user_stats/signed_public_dashboard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h1>Signed dashboards without parameters</h1>
1717
}
1818
}
1919

20-
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
20+
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
2121

2222
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
2323
</pre>

django/embedded_analytics/user_stats/views.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
METABASE_SITE_URL = "localhost:3000"
88
METABASE_SECRET_KEY = "a1c0952f3ff361f1e7dd8433a0a50689a004317a198ecb0a67ba90c73c27a958"
99

10-
10+
def get_token(payload):
11+
return jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
1112

1213
def index(request):
1314
return render(request,
@@ -21,9 +22,7 @@ def signed_public_dashboard(request):
2122
}
2223
}
2324

24-
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
25-
26-
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
25+
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + get_token(payload) + "#bordered=true"
2726

2827
return render(request,
2928
'user_stats/signed_public_dashboard.html',
@@ -37,9 +36,7 @@ def signed_chart(request, user_id):
3736
}
3837
}
3938

40-
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
41-
42-
iframeUrl = METABASE_SITE_URL + "/embed/question/" + token + "#bordered=true"
39+
iframeUrl = METABASE_SITE_URL + "/embed/question/" + get_token(payload) + "#bordered=true"
4340

4441
if request.user.is_superuser:
4542
# always show admins user stats
@@ -62,9 +59,7 @@ def signed_dashboard(request, user_id):
6259
}
6360
}
6461

65-
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
66-
67-
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
62+
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + get_token(payload) + "#bordered=true"
6863

6964
if request.user.is_superuser:
7065
# always show admins user stats
Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
1-
# README
1+
# Laravel app
22

3-
1. Install dependencies: `composer install`. The package `lcobucci/jwt` has already been added
4-
2. See the Example Code in `routes/web.php`
5-
3. See the Example View in `resources/views/welcome.blade.php`
3+
This Laravel application demonstrates a simple, barebones Metabase dashboard embedded in a web application.
64

7-
You can test it by running `php artisan serve` from the root of the Laravel application and opening http://localhost:8000.
5+
## Prerequisites
6+
7+
- **Metabase**. You should have already completed the setup detailed in the [README](../../README.md) for this repository, which shows you how to get an instance of Metabase up and running in the [metabase](./metabase) directory of this repository.
8+
9+
- **Composer**. You'll need [Composer](https://getcomposer.org/) to manage PHP packages.
10+
11+
- **Laravel**. You'll need to have [Laravel](https://laravel.com/) installed on your machine.
12+
13+
## Set up the Laravel application
14+
15+
1. Start a new terminal session, change into this directory, and install the application dependencies using the command `composer install`. (The package `lcobucci/jwt` has already been added.)
16+
17+
Note: if you just installed Composer using the default filename for Composer to this directory, you may need to run:
18+
19+
```shell
20+
php composer.phar install
21+
```
22+
23+
2. Generate an application key. First, create a .env file by copying the example env file.
24+
25+
```shell
26+
cp .env.example .env
27+
```
28+
29+
Then generate the key.
30+
31+
```shell
32+
php artisan key:generate
33+
```
34+
35+
This command will write the key to your new .env file.
36+
37+
3. To start the application, run:
38+
39+
```shell
40+
php artisan serve
41+
```
42+
43+
4. Open your browser to [localhost:8000](http://localhost:8000) to see the app in action.
44+
45+
Explore the app to learn more about embedding Metabase charts and dashboards in applications. You can also check out the links to more documentation in the parent repository's main [README](../../README.md).
46+
47+
## Example embedding code
48+
49+
- **Code**. You can find example code for embedding Metabase in [routes/web.php](routes/web.php).
50+
51+
- **View**. You can find an example view in [resources/views/welcome.blade.php](resources/views/welcome.blade.php).

0 commit comments

Comments
 (0)