|
2 | 2 | All notable changes to `dash` will be documented in this file.
|
3 | 3 | This project adheres to [Semantic Versioning](https://semver.org/).
|
4 | 4 |
|
| 5 | +## [Unreleased] |
| 6 | + |
| 7 | +- [#1763](https://github.com/plotly/dash/pull/1763): |
| 8 | + ## Dash and Dash Renderer |
| 9 | + |
| 10 | + - `Input`, `State`, and `Output` now accept components instead of ID strings and Dash `callback` will auto-generate the component's ID under-the-hood if not supplied. This allows usage like: |
| 11 | + |
| 12 | + ```python |
| 13 | + my_input = dcc.Input() |
| 14 | + my_output = html.Div() |
| 15 | + app.layout = html.Div([my_input, my_output]) |
| 16 | + |
| 17 | + @dash.callback(Output(my_output, 'children'), Input(my_input, 'value')) |
| 18 | + def update(value): |
| 19 | + return f'You have entered {value}' |
| 20 | + ``` |
| 21 | + |
| 22 | + Or, if using Python >=3.8 you can use the `:=` walrus operator: |
| 23 | + ```python |
| 24 | + app.layout = html.Div([ |
| 25 | + my_input := dcc.Input(), |
| 26 | + my_output := html.Div() |
| 27 | + ]) |
| 28 | + |
| 29 | + @dash.callback(Output(my_output, 'children'), Input(my_input, 'value')) |
| 30 | + def update(value): |
| 31 | + return f'You have entered {value}' |
| 32 | + |
| 33 | + ``` |
| 34 | + ## Dash Core Components |
| 35 | + |
| 36 | + ### Rearranged Keyword Arguments & Flexible Types |
| 37 | + **`Dropdown`, `RadioItem`, and `Checklist`** |
| 38 | + - Rearranged Keyword Arguments - `options` & `value` are now the first two keywords which means they can be supplied as positional arguments without the keyword. Supplying the keywords (`options=` and `value=`) is still supported. |
| 39 | + - Flexible Types - `options` can be supplied in two new forms: |
| 40 | + 1. An array of `string|number|bool` where `label` and `value` are equal to the items in the list. |
| 41 | + 2. A dictionary where the keys and values set as `value` and `label` respectively. |
| 42 | + |
| 43 | + Before: |
| 44 | + |
| 45 | + ```python |
| 46 | + dcc.Dropdown( |
| 47 | + options=[ |
| 48 | + {'label': 'New York', 'value': 'New York'}, |
| 49 | + {'label': 'Montreal', 'value': 'Montreal'}, |
| 50 | + ], |
| 51 | + value='New York' |
| 52 | + ) |
| 53 | + ``` |
| 54 | + or |
| 55 | + |
| 56 | + ```python |
| 57 | + dcc.Dropdown( |
| 58 | + options=[ |
| 59 | + {'label': 'New York', 'value': 'NYC'}, |
| 60 | + {'label': 'Montreal', 'value': 'MTL'}, |
| 61 | + ], |
| 62 | + value='New York' |
| 63 | + ) |
| 64 | + ``` |
| 65 | + |
| 66 | + After: |
| 67 | + |
| 68 | + ```python |
| 69 | + dcc.Dropdown(['New York', 'Montreal'], 'New York') |
| 70 | + ``` |
| 71 | + Or |
| 72 | + |
| 73 | + ```python |
| 74 | + dcc.Dropdown({'NYC': 'New York', 'MTL': 'Montreal'}, 'New York') |
| 75 | + ``` |
| 76 | + |
| 77 | + **`RangeSlider` & `Slider`** |
| 78 | + - Rearranged Keyword Arugments - `min`, `max`, and `step` are now the first three keyword arguments which means they can be supplied as positional arguments without the keyword. |
| 79 | + - Flexible Types |
| 80 | + - `step` will be calculated implicitly if not given. |
| 81 | + - `marks` will be auto generated if not given. It will use `min` and `max` and will respect `step` if supplied. Auto generated marks labels are SI unit formatted. Around 5 human-readable marks will be created. |
| 82 | + - To remove the Slider's marks, set `marks=None`. |
| 83 | + |
| 84 | + Before: |
| 85 | + |
| 86 | + ```python |
| 87 | + dcc.Slider(marks={1: 2, 2: 2, 3: 3}) |
| 88 | + ``` |
| 89 | + |
| 90 | + After: |
| 91 | + ```python |
| 92 | + dcc.Slider(min=1, max=3, step=1) |
| 93 | + ``` |
| 94 | + Or equivalently: |
| 95 | + ```python |
| 96 | + dcc.Slider(1, 3, 1) |
| 97 | + ``` |
| 98 | + Step can also be omitted and the `Slider` will attempt to create a nice, human readable step with SI units and around 5 marks: |
| 99 | + ```python |
| 100 | + dcc.Slider(0, 100) |
| 101 | + ``` |
| 102 | + |
| 103 | + The SI units used in `marks` are: |
| 104 | + |
| 105 | + * `z` - zepto, 10⁻²¹ |
| 106 | + * `a` - atto, 10⁻¹⁸ |
| 107 | + * `f` - femto, 10⁻¹⁵ |
| 108 | + * `p` - pico, 10⁻¹² |
| 109 | + * `n` - nano, 10⁻⁹ |
| 110 | + * `µ` - micro, 10⁻⁶ |
| 111 | + * `m` - milli, 10⁻³ |
| 112 | + * `` (none) - 10⁰ |
| 113 | + * `k` - kilo, 10³ |
| 114 | + * `M` - mega, 10⁶ |
| 115 | + * `G` - giga, 10⁹ |
| 116 | + * `T` - tera, 10¹² |
| 117 | + * `P` - peta, 10¹⁵ |
| 118 | + * `E` - exa, 10¹⁸ |
| 119 | + * `Z` - zetta, 10²¹ |
| 120 | + |
| 121 | + **`DataTable`** |
| 122 | + |
| 123 | + - Rearranged Keyword Arguments - `data` and `columns` the first twokeyword arguments which means they can be supplied as positional arguments without the keyword. |
| 124 | + - Inferred Properties - If `columns` isn't supplied then it is extracted from the the first row in `data` |
| 125 | + |
| 126 | + Before: |
| 127 | + |
| 128 | + ```python |
| 129 | + dash_table.DataTable(data=df.to_dict('records'), columns=[{'name': i, 'id': i} for i in df.columns]) |
| 130 | + ``` |
| 131 | + After: |
| 132 | + |
| 133 | + ```python |
| 134 | + dash_table.DataTable(data=df.to_dict('records')) |
| 135 | + ``` |
| 136 | + |
| 137 | + ### New Component Properties |
| 138 | + |
| 139 | + **`Checklist` & `RadioItems`** |
| 140 | + |
| 141 | + - A new property `inline` appends `display: inline-block` to `labelStyle`. |
| 142 | + |
| 143 | + ```python |
| 144 | + dcc.Checklist(inline=True) |
| 145 | + ``` |
| 146 | + |
5 | 147 | ## [2.0.0] - 2021-08-03
|
6 | 148 |
|
7 | 149 | ## Dash and Dash Renderer
|
|
0 commit comments