AnnMarieW / dash-app-gallery

Dash Examples Index
https://dash-example-index.herokuapp.com/
MIT License
59 stars 24 forks source link

Update key-figures-finland #128

Closed tuopouk closed 1 year ago

tuopouk commented 1 year ago

Updated the filename and ids

AnnMarieW commented 1 year ago

This looks good now and it's ready for Adam's review.
Would you like to format it with Black? If not we can do that after it's merged.

Thanks!

tuopouk commented 1 year ago

I just formatted it with Black.

tuopouk commented 1 year ago

@Coding-with-Adam It should be just requests.get(<json-url>).json()

I did some research and there seems to be both encoding and parsing issues.

I tried using my own repo's json url, and it worked.

Here's how I read the csv

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/Dash-Examle-Index/key_figures_regions.csv', encoding="utf-8").rename(columns={"Region 2021": "Region"}).set_index("Region")

Here's how I read the json. Reading that raw json you mentioned lead to JSONDecodeError r = requests.get('https://raw.githubusercontent.com/tuopouk/dash-app-gallery/main/assets/regions.json') r.encoding='utf-8' regions_json = r.json()

Basically the encoding on the csv and json should both be utf-8. I guess it should start to work if the files were formatted somehow, say, on Notepad++.

tuopouk commented 1 year ago

@Coding-with-Adam Could you please change the reading csv part to have encoding to utf-8? If it's not the same encoding, some regions will not be rendered on the map. df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/Dash-Examle-Index/key_figures_regions.csv', encoding="utf-8").rename(columns={"Region 2021": "Region"}).set_index("Region")

Now it should work as expected.

Coding-with-Adam commented 1 year ago

, encoding="utf-8").rename(columns={"Region 2021": "Region"}).set_index("Region")

Done. Sorry I missed that.

@tuopouk I also tweaked the line of code that originally replaced the comma with a space. This was a suggestion by Ann that I agreed with.

Let me know if you like the final code/result. And I will merge the app.

tuopouk commented 1 year ago

@Coding-with-Adam Looks great and the regions render correctly as well as their names. It's actually better to have comma as a separator. It would be different if the app was non-English. I guess you can merge from my part. Thanks!

Coding-with-Adam commented 1 year ago

Thanks for adding that file back, @tuopouk