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
HTML | `text/html` | `to_html()` | See notes on [HTML output](#html-output)
56
57
CSV | `text/csv` | `to_csv()` |
57
58
TXT | `text/plain` | `to_csv()` | Useful for testing, as most browsers will download a CSV file instead of displaying it
58
59
JSON | `application/json` | `to_json()` | [`date_format` and `orient`][to_json] can be provided in URL (e.g. `/path.json?orient=columns`)
@@ -76,7 +77,7 @@ pip install rest-pandas
76
77
77
78
**NOTE:** Django REST Pandas relies on pandas, which itself relies on NumPy and other scientific Python libraries written in C. This is usually fine, since pip can use Python Wheels to install precompiled versions. If you are having trouble installing DRP due to dependency issues, you may need to pre-install pandas using apt or conda.
78
79
79
-
### Usage Example
80
+
### Usage Examples
80
81
81
82
#### No Model
82
83
@@ -257,6 +258,26 @@ Alternately, you can disable date serialization globally by setting `DATETIME_FO
257
258
DATE_FORMAT=None
258
259
```
259
260
261
+
#### HTML Output
262
+
263
+
The HTML renderer provides the ability to create an interactive view that shares the same URL as your data API. The dataframe is processed by `to_html()`, then passed to [TemplateHTMLRenderer] with the following context:
264
+
265
+
context variable | description
266
+
-----------------|------------------
267
+
`table` | Output `<table>` from `to_html()`
268
+
`name` | View name
269
+
`description` | View description
270
+
`url` | Current URL Path (without parameters)
271
+
`url_params` | URL parameters
272
+
`available_formats` | Array of allowed extensions (e.g. `'csv'`, `'json'`, `'xlsx'`)
273
+
`wq_chart_type` | Recommended chart type (for use with [wq/chartapp.js], see below)
274
+
275
+
As with `TemplateHTMLRenderer`, the template name is controlled by the view. If you are using DRP together with the [wq framework], you can leverage the default [mustache/rest_pandas.html] template, which is designed for use with the [wq/chartapp.js] plugin. Otherwise, you will probably want to provide a custom template and/or set `template_name` on the view.
276
+
277
+
If you need to do a lot of customization, and/or you don't really need the entire dataframe rendered in a `<table>`, you can always create another view for the interface and make the `PandasView` only handle the API.
278
+
279
+
> Note: For backwards compatibility, `PandasHTMLRenderer` is only included in the default `PANDAS_RENDERERS` if `rest_pandas` is listed in your installed apps.
280
+
260
281
## Building Interactive Charts
261
282
262
283
In addition to use as a data export tool, DRP is well-suited for creating data API backends for interactive charts. In particular, DRP can be used with [d3.js], [wq/pandas.js], and [wq/chart.js], to create interactive time series, scatter, and box plot charts - as well as any of the infinite other charting possibilities d3.js provides.
@@ -283,7 +304,7 @@ function render(error, data) {
283
304
});
284
305
```
285
306
286
-
DRP includes three custom serializers with `transform_dataframe()` functions that address common use cases. These serializer classes can be leveraged by assigning them to `pandas_serializer_class` on your view.
307
+
DRP includes three custom serializers with `transform_dataframe()` functions that address common use cases. These serializer classes can be leveraged by assigning them to `pandas_serializer_class` on your view. If you are using the [wq framework], these serializers can automatically leverage DRP's default [HTML template](#html-output) together with [wq/chartapp.js] to provide interactive charts. If you are not using the full wq framework, you can still use [wq/pandas.js] and [wq/chart.js] directly with the CSV output of these serializers.
287
308
288
309
For documentation purposes, the examples below assume the following dataset:
0 commit comments