admintutorial.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. .. Licensed to the Apache Software Foundation (ASF) under one
  2. or more contributor license agreements. See the NOTICE file
  3. distributed with this work for additional information
  4. regarding copyright ownership. The ASF licenses this file
  5. to you under the Apache License, Version 2.0 (the
  6. "License"); you may not use this file except in compliance
  7. with the License. You may obtain a copy of the License at
  8. .. http://www.apache.org/licenses/LICENSE-2.0
  9. .. Unless required by applicable law or agreed to in writing,
  10. software distributed under the License is distributed on an
  11. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, either express or implied. See the License for the
  13. specific language governing permissions and limitations
  14. under the License.
  15. Creating your first dashboard
  16. =============================
  17. This tutorial targets someone who wants to create charts and dashboards
  18. in Superset. We'll show you how to connect Superset
  19. to a new database and configure a table in that database for analysis. You'll
  20. also explore the data you've exposed and add a visualization to a dashboard
  21. so that you get a feel for the end-to-end user experience.
  22. Connecting to a new database
  23. ----------------------------
  24. We assume you already have a database configured and can connect to it from the
  25. instance on which you’re running Superset. If you’re just testing Superset and
  26. want to explore sample data, you can load some
  27. `sample PostgreSQL datasets <https://wiki.postgresql.org/wiki/Sample_Databases>`_
  28. into a fresh DB, or configure the
  29. `example weather data <https://github.com/dylburger/noaa-ghcn-weather-data>`_
  30. we use here.
  31. Under the **Sources** menu, select the *Databases* option:
  32. .. image:: _static/images/tutorial/tutorial_01_sources_database.png
  33. :scale: 70%
  34. On the resulting page, click on the green plus sign, near the top right:
  35. .. image:: _static/images/tutorial/tutorial_02_add_database.png
  36. :scale: 70%
  37. You can configure a number of advanced options on this page, but for
  38. this walkthrough, you’ll only need to do **two things**:
  39. 1. Name your database connection:
  40. .. image:: _static/images/tutorial/tutorial_03_database_name.png
  41. :scale: 70%
  42. 2. Provide the SQLAlchemy Connection URI and test the connection:
  43. .. image:: _static/images/tutorial/tutorial_04_sqlalchemy_connection_string.png
  44. :scale: 70%
  45. This example shows the connection string for our test weather database.
  46. As noted in the text below the URI, you should refer to the SQLAlchemy
  47. documentation on
  48. `creating new connection URIs <https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#database-urls>`_
  49. for your target database.
  50. Click the **Test Connection** button to confirm things work end to end.
  51. Once Superset can successfully connect and authenticate, you should see
  52. a popup like this:
  53. .. image:: _static/images/tutorial/tutorial_05_connection_popup.png
  54. :scale: 50%
  55. Moreover, you should also see the list of tables Superset can read from
  56. the schema you’re connected to, at the bottom of the page:
  57. .. image:: _static/images/tutorial/tutorial_06_list_of_tables.png
  58. :scale: 70%
  59. If the connection looks good, save the configuration by clicking the **Save**
  60. button at the bottom of the page:
  61. .. image:: _static/images/tutorial/tutorial_07_save_button.png
  62. :scale: 70%
  63. Adding a new table
  64. ------------------
  65. Now that you’ve configured a database, you’ll need to add specific tables
  66. to Superset that you’d like to query.
  67. Under the **Sources** menu, select the *Tables* option:
  68. .. image:: _static/images/tutorial/tutorial_08_sources_tables.png
  69. :scale: 70%
  70. On the resulting page, click on the green plus sign, near the top left:
  71. .. image:: _static/images/tutorial/tutorial_09_add_new_table.png
  72. :scale: 70%
  73. You only need a few pieces of information to add a new table to Superset:
  74. * The name of the table
  75. .. image:: _static/images/tutorial/tutorial_10_table_name.png
  76. :scale: 70%
  77. * The target database from the **Database** drop-down menu (i.e. the one
  78. you just added above)
  79. .. image:: _static/images/tutorial/tutorial_11_choose_db.png
  80. :scale: 70%
  81. * Optionally, the database schema. If the table exists in the “default” schema
  82. (e.g. the *public* schema in PostgreSQL or Redshift), you can leave the schema
  83. field blank.
  84. Click on the **Save** button to save the configuration:
  85. .. image:: _static/images/tutorial/tutorial_07_save_button.png
  86. :scale: 70%
  87. When redirected back to the list of tables, you should see a message indicating
  88. that your table was created:
  89. .. image:: _static/images/tutorial/tutorial_12_table_creation_success_msg.png
  90. :scale: 70%
  91. This message also directs you to edit the table configuration. We’ll edit a limited
  92. portion of the configuration now - just to get you started - and leave the rest for
  93. a more advanced tutorial.
  94. Click on the edit button next to the table you’ve created:
  95. .. image:: _static/images/tutorial/tutorial_13_edit_table_config.png
  96. :scale: 70%
  97. On the resulting page, click on the **List Table Column** tab. Here, you’ll define the
  98. way you can use specific columns of your table when exploring your data. We’ll run
  99. through these options to describe their purpose:
  100. * If you want users to group metrics by a specific field, mark it as **Groupable**.
  101. * If you need to filter on a specific field, mark it as **Filterable**.
  102. * Is this field something you’d like to get the distinct count of? Check the **Count
  103. Distinct** box.
  104. * Is this a metric you want to sum, or get basic summary statistics for? The **Sum**,
  105. **Min**, and **Max** columns will help.
  106. * The **is temporal** field should be checked for any date or time fields. We’ll cover
  107. how this manifests itself in analyses in a moment.
  108. Here’s how we’ve configured fields for the weather data. Even for measures like the
  109. weather measurements (precipitation, snowfall, etc.), it’s ideal to group and filter
  110. by these values:
  111. .. image:: _static/images/tutorial/tutorial_14_field_config.png
  112. As with the configurations above, click the **Save** button to save these settings.
  113. Exploring your data
  114. -------------------
  115. To start exploring your data, simply click on the table name you just created in
  116. the list of available tables:
  117. .. image:: _static/images/tutorial/tutorial_15_click_table_name.png
  118. By default, you’ll be presented with a Table View:
  119. .. image:: _static/images/tutorial/tutorial_16_datasource_chart_type.png
  120. Let’s walk through a basic query to get the count of all records in our table.
  121. First, we’ll need to change the **Since** filter to capture the range of our data.
  122. You can use simple phrases to apply these filters, like "3 years ago":
  123. .. image:: _static/images/tutorial/tutorial_17_choose_time_range.png
  124. The upper limit for time, the **Until** filter, defaults to "now", which may or may
  125. not be what you want.
  126. Look for the Metrics section under the **GROUP BY** header, and start typing "Count"
  127. - you’ll see a list of metrics matching what you type:
  128. .. image:: _static/images/tutorial/tutorial_18_choose_metric.png
  129. Select the *COUNT(\*)* metric, then click the green **Query** button near the top
  130. of the explore:
  131. .. image:: _static/images/tutorial/tutorial_19_click_query.png
  132. You’ll see your results in the table:
  133. .. image:: _static/images/tutorial/tutorial_20_count_star_result.png
  134. Let’s group this by the *weather_description* field to get the count of records by
  135. the type of weather recorded by adding it to the *Group by* section:
  136. .. image:: _static/images/tutorial/tutorial_21_group_by.png
  137. and run the query:
  138. .. image:: _static/images/tutorial/tutorial_22_group_by_result.png
  139. Let’s find a more useful data point: the top 10 times and places that recorded the
  140. highest temperature in 2015.
  141. We replace *weather_description* with *latitude*, *longitude* and *measurement_date* in the
  142. *Group by* section:
  143. .. image:: _static/images/tutorial/tutorial_23_group_by_more_dimensions.png
  144. And replace *COUNT(\*)* with *max__measurement_flag*:
  145. .. image:: _static/images/tutorial/tutorial_24_max_metric.png
  146. The *max__measurement_flag* metric was created when we checked the box under **Max** and
  147. next to the *measurement_flag* field, indicating that this field was numeric and that
  148. we wanted to find its maximum value when grouped by specific fields.
  149. In our case, *measurement_flag* is the value of the measurement taken, which clearly
  150. depends on the type of measurement (the researchers recorded different values for
  151. precipitation and temperature). Therefore, we must filter our query only on records
  152. where the *weather_description* is equal to "Maximum temperature", which we do in
  153. the **Filters** section at the bottom of the explore:
  154. .. image:: _static/images/tutorial/tutorial_25_max_temp_filter.png
  155. Finally, since we only care about the top 10 measurements, we limit our results to
  156. 10 records using the *Row limit* option under the **Options** header:
  157. .. image:: _static/images/tutorial/tutorial_26_row_limit.png
  158. We click **Query** and get the following results:
  159. .. image:: _static/images/tutorial/tutorial_27_top_10_max_temps.png
  160. In this dataset, the maximum temperature is recorded in tenths of a degree Celsius.
  161. The top value of 1370, measured in the middle of Nevada, is equal to 137 C, or roughly
  162. 278 degrees F. It’s unlikely this value was correctly recorded. We’ve already been able
  163. to investigate some outliers with Superset, but this just scratches the surface of what
  164. we can do.
  165. You may want to do a couple more things with this measure:
  166. * The default formatting shows values like 1.37k, which may be difficult for some
  167. users to read. It’s likely you may want to see the full, comma-separated value.
  168. You can change the formatting of any measure by editing its config (*Edit Table
  169. Config > List Sql Metric > Edit Metric > D3Format*)
  170. * Moreover, you may want to see the temperature measurements in plain degrees C,
  171. not tenths of a degree. Or you may want to convert the temperature to degrees
  172. Fahrenheit. You can change the SQL that gets executed against the database, baking
  173. the logic into the measure itself (*Edit Table Config > List Sql Metric > Edit
  174. Metric > SQL Expression*)
  175. For now, though, let’s create a better visualization of these data and add it to
  176. a dashboard.
  177. We change the Chart Type to "Distribution - Bar Chart":
  178. .. image:: _static/images/tutorial/tutorial_28_bar_chart.png
  179. Our filter on Maximum temperature measurements was retained, but the query and
  180. formatting options are dependent on the chart type, so you’ll have to set the
  181. values again:
  182. .. image:: _static/images/tutorial/tutorial_29_bar_chart_series_metrics.png
  183. You should note the extensive formatting options for this chart: the ability to
  184. set axis labels, margins, ticks, etc. To make the data presentable to a broad
  185. audience, you’ll want to apply many of these to slices that end up in dashboards.
  186. For now, though, we run our query and get the following chart:
  187. .. image:: _static/images/tutorial/tutorial_30_bar_chart_results.png
  188. :scale: 70%
  189. Creating a slice and dashboard
  190. ------------------------------
  191. This view might be interesting to researchers, so let’s save it. In Superset,
  192. a saved query is called a **Slice**.
  193. To create a slice, click the **Save as** button near the top-left of the
  194. explore:
  195. .. image:: _static/images/tutorial/tutorial_19_click_query.png
  196. A popup should appear, asking you to name the slice, and optionally add it to a
  197. dashboard. Since we haven’t yet created any dashboards, we can create one and
  198. immediately add our slice to it. Let’s do it:
  199. .. image:: _static/images/tutorial/tutorial_31_save_slice_to_dashboard.png
  200. :scale: 70%
  201. Click Save, which will direct you back to your original query. We see that
  202. our slice and dashboard were successfully created:
  203. .. image:: _static/images/tutorial/tutorial_32_save_slice_confirmation.png
  204. :scale: 70%
  205. Let’s check out our new dashboard. We click on the **Dashboards** menu:
  206. .. image:: _static/images/tutorial/tutorial_33_dashboard.png
  207. and find the dashboard we just created:
  208. .. image:: _static/images/tutorial/tutorial_34_weather_dashboard.png
  209. Things seemed to have worked - our slice is here!
  210. .. image:: _static/images/tutorial/tutorial_35_slice_on_dashboard.png
  211. :scale: 70%
  212. But it’s a bit smaller than we might like. Luckily, you can adjust the size
  213. of slices in a dashboard by clicking, holding and dragging the bottom-right
  214. corner to your desired dimensions:
  215. .. image:: _static/images/tutorial/tutorial_36_adjust_dimensions.gif
  216. :scale: 120%
  217. After adjusting the size, you’ll be asked to click on the icon near the
  218. top-right of the dashboard to save the new configuration.
  219. Congrats! You’ve successfully linked, analyzed, and visualized data in Superset.
  220. There are a wealth of other table configuration and visualization options, so
  221. please start exploring and creating slices and dashboards of your own.