dash-table icon indicating copy to clipboard operation
dash-table copied to clipboard

Include space before SI-prefix

Open asnyv opened this issue 5 years ago • 8 comments

In the SI system, prefix and units should be written after a space (see e.g.: https://en.wikipedia.org/wiki/International_System_of_Units#General_rules) I haven't found an option to do this. The issue can be reproduced by the example below where I get a space between the prefix (e.g. k) and the unit W. Alternatively I could of course skip the space before the W, but I cannot find a way to add a space between the last digit and the SI-prefix.

import dash
import dash_table
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

app = dash.Dash(__name__)
app.layout = dash_table.DataTable(
    id='table',
    columns=[{'name': i, 'id': i, 'type': 'numeric', 'format': {'locale': {'symbol': ['', ' W']}, 'specifier': '$.3s'}} for i in df.columns],
    data=df.to_dict('records'),
)

if __name__ == '__main__':
    app.run_server(debug=True)

image

asnyv avatar Mar 05 '20 12:03 asnyv

(I responded to your community forum post about this here: https://community.plot.ly/t/dash-table-numeric-formatting-symbol-use/35784/3)

chriddyp avatar Mar 05 '20 14:03 chriddyp

(response was given in the community post)

asnyv avatar Mar 05 '20 15:03 asnyv

Hi, @chriddyp could it be that this issue is inherited from d3's format? From what I can see, d3 also writes without a whitespace.

asnyv avatar Mar 09 '20 08:03 asnyv

Another bug I have discovered regarding the number formatting: If the if "prefix" is set together with "locale": "symbol": ['a', 'b'], the last element 'b' of the "symbol" list is written before the prefix, while if "prefix" is not set, 'b' is written after the prefix (this behavior is the most useful for units). Also a bit annoying that defining "prefix" switches from significant digits to number of decimals, but this seems intended, so not a bug.

examples: 1000 with 'format': {'locale': {'symbol': ['', 'W']}, 'nully': '', 'prefix': 10**3, 'specifier': '$.3s'} is written as 1.000Wk 1000 with 'format': {'locale': {'symbol': ['', 'W']}, 'nully': '', 'specifier': '$.3s'} is written as 1.00kW

As mentioned: Ideally I would like to write e.g. 1.00 kW

asnyv avatar Mar 10 '20 11:03 asnyv

Just in case: it wasn't working for me until I added the 'type': 'numeric', might be obvious to some, but turns out this isn't optional.

paulbeelen avatar May 09 '20 12:05 paulbeelen

@asnyv I'm surprised this issue didn't get more attention! Maybe SI is still unknown to many. :joy:

Did you find a workaround since you posted? :blush:

Peque avatar Nov 15 '21 13:11 Peque

@Peque No, I haven't 🙄 Ended up writing the unit in the column headers (e.g. W) and living with the e.g. 1.3M for the table values...

But yes, I'm a bit surprised myself 😅 Would also have been nice to be able to set SI as the overall standard format for an app. Annoying with e.g. B popping up instead of G for 1e9 if you haven't remembered to specify the SI syntax.

asnyv avatar Nov 15 '21 13:11 asnyv

For future reference, just in case I get an answer there, here is a question I posted in SO about this topic.

Peque avatar Nov 15 '21 14:11 Peque