Using Dash library for python

243 views
Skip to first unread message

gilles....@gmail.com

unread,
Oct 16, 2023, 12:16:28 PM10/16/23
to golden-cheetah-users
Hello

I would like to use Dash lib in a python chart.

I created a python chart containing the example code in https://dash.plotly.com/dash-core-components/input

Unfortunately, Dash is not available... How can I overcome this issue ?

Thanks in advance

Regards

Gilles

Ale Martinez

unread,
Oct 16, 2023, 12:23:46 PM10/16/23
to golden-cheetah-users
El lunes, 16 de octubre de 2023 a la(s) 13:16:28 UTC-3, gilles....@gmail.com escribió:
Hello

I would like to use Dash lib in a python chart.

I created a python chart containing the example code in https://dash.plotly.com/dash-core-components/input

Unfortunately, Dash is not available... How can I overcome this issue ?

To install Python packages see the Working with Python entry in the wiki, for Dash see also  https://groups.google.com/g/golden-cheetah-users/c/nNyKZc15VrA/m/o9s0X6J1AwAJ

gilles....@gmail.com

unread,
Oct 16, 2023, 3:47:13 PM10/16/23
to golden-cheetah-users
Thanks, I installed dash in some python 3.7 environment using miniconda, and I set the option > General > Python home to "c:\gilles\programs\miniconda3\envs\freecad37\"

Unfortunately, dash module is still not found.

Ale Martinez

unread,
Oct 16, 2023, 5:45:21 PM10/16/23
to golden-cheetah-users
El lunes, 16 de octubre de 2023 a la(s) 16:47:13 UTC-3, gilles....@gmail.com escribió:
Thanks, I installed dash in some python 3.7 environment using miniconda, and I set the option > General > Python home to "c:\gilles\programs\miniconda3\envs\freecad37\"

Not sure about miniconda environments, but standard Python ones (venv, virtualenv) don't work with Python embedding as used by GoldenCheetah. 

Ale Martinez

unread,
Oct 16, 2023, 6:31:09 PM10/16/23
to golden-cheetah-users
BTW, all of the above and basically all we know about the Python chart is documented in https://github.com/GoldenCheetah/GoldenCheetah/wiki/UG_Special-Topics_Working-with-Python#using-the-python-chart, I strongly suggest to carefully read that document if you plan to use a separate Python install. 

gilles....@gmail.com

unread,
Oct 17, 2023, 10:32:05 AM10/17/23
to golden-cheetah-users
Thanks

I did another installation of Python, with many difficulties... I have several python packages that I do not know how to choose among them  with c:\Windows\py.exe

I installed 3.7.9 64 bits version from web installer (to C:\Users\xxx\AppData\Local\Programs\Python\Python37 )
Then I installed pip from command line : C:\Users\xxx\AppData\Local\Programs\Python\Python37\python.exe c:\gilles\bin\get-pip.py
Then I installed dash with :  run  C:\Users\xxx\AppData\Local\Programs\Python\Python37\python.exe -m pip install dash
Then I changed the GC Python interpreter in Options > General

The code still does not Work : "import dash" works, but the code ends with error Capture.PNG


from dash import Dash, dcc, html, Input, Output, callback
app = Dash(__name__) ALLOWED_TYPES = ( "text", "number", "password", "email", "search", "tel", "url", "range", "hidden", ) app.layout = html.Div( [ dcc.Input( id="input_{}".format(_), type=_, placeholder="input type {}".format(_), ) for _ in ALLOWED_TYPES ] + [html.Div(id="out-all-types")] ) @callback( Output("out-all-types", "children"), [Input("input_{}".format(_), "value") for _ in ALLOWED_TYPES], ) def cb_render(*vals): return " | ".join((str(val) for val in vals if val)) if __name__ == "__main__": app.run(debug=True)

Ale Martinez

unread,
Oct 17, 2023, 11:33:08 AM10/17/23
to golden-cheetah-users
El martes, 17 de octubre de 2023 a la(s) 11:32:05 UTC-3, gilles....@gmail.com escribió:
Thanks

I did another installation of Python, with many difficulties... I have several python packages that I do not know how to choose among them  with c:\Windows\py.exe

I installed 3.7.9 64 bits version from web installer (to C:\Users\xxx\AppData\Local\Programs\Python\Python37 )
Then I installed pip from command line : C:\Users\xxx\AppData\Local\Programs\Python\Python37\python.exe c:\gilles\bin\get-pip.py
Then I installed dash with :  run  C:\Users\xxx\AppData\Local\Programs\Python\Python37\python.exe -m pip install dash
Then I changed the GC Python interpreter in Options > General

The code still does not Work : "import dash" works, but the code ends with error Capture.PNG

Since the example you are testing doesn't use the GC api you could try running it directly from the Python interpreter to debug your install independently of GC before trying the embedding.

gilles....@gmail.com

unread,
Oct 18, 2023, 3:36:34 AM10/18/23
to golden-cheetah-users
I run this example with the Python installation, using the command "python c:\gilles\dcc_input_example.py".
It works, dash server gives access to the expected web page.

Here follows a screen capture:
Capture.PNG

Ale Martinez

unread,
Oct 19, 2023, 10:04:41 AM10/19/23
to golden-cheetah-users
El miércoles, 18 de octubre de 2023 a la(s) 04:36:34 UTC-3, gilles....@gmail.com escribió:
I run this example with the Python installation, using the command "python c:\gilles\dcc_input_example.py".
It works, dash server gives access to the expected web page.

GFY, then you can point GC to that Python instance and try again, if you see an error in the console you can go to the reported file/line to try to understand what is happening.

Mark Liversedge

unread,
Oct 19, 2023, 11:58:23 AM10/19/23
to golden-cheetah-users
It might be worth adding a note to the wiki that calls made from a Python script must not block (eg. start a server, wait for user input)

Ale Martinez

unread,
Oct 19, 2023, 12:31:56 PM10/19/23
to golden-cheetah-users
El jueves, 19 de octubre de 2023 a la(s) 12:58:23 UTC-3, Mark Liversedge escribió:
It might be worth adding a note to the wiki that calls made from a Python script must not block (eg. start a server, wait for user input)

Agree and I will do it.
Dash used to work using Python threading module to start the server as illustrated by the chart example included in the conversation I linked in my first answer, but current version seems to be failing when the Dash object is instantiated -well before the server is started- likely due to introspection on the calling stack, but I have not tested myself.

gilles....@gmail.com

unread,
Oct 20, 2023, 10:47:12 AM10/20/23
to golden-cheetah-users
When GC points to this installation, the python chart generates the error :
Capture (1).png

Mark & Ale : indeed, the dash/python script starts a server... 

My idea is to use dash to implement a user input that represent the name of a segment (combo box selection, or text input) connected to an event which updates the chart of segment's power & duration timeline...

Regards

Remco Boerwinkel

unread,
Oct 20, 2023, 11:21:30 AM10/20/23
to golden-cheetah-users
Hi Gilles,

First i must say i have not updated to the latest GC so not sure if things are the same with python and treading. I'm running on an older build:
image.png

My experience with dash in combination with GC is that it is tricky with treading indeed as Mark and Ale said . Also when other charts/dash pages are loaded after a dash server has been started.
In my script I try to kill other dash instances before starting a new one. An example you can try is uploaded: 

image.png
Hope this helps, and of course try on your own risk 🤞

Kind regards,
Remco

--
_______________________________________________
Golden-Cheetah-Users mailing list
golden-che...@googlegroups.com
http://groups.google.com/group/golden-cheetah-users?hl=en
---
You received this message because you are subscribed to the Google Groups "golden-cheetah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golden-cheetah-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golden-cheetah-users/0e6b9ca7-7ccb-496d-994f-21a985cacaf2n%40googlegroups.com.

Ale Martinez

unread,
Oct 20, 2023, 1:43:16 PM10/20/23
to golden-cheetah-users
El viernes, 20 de octubre de 2023 a la(s) 12:21:30 UTC-3, Remco Boerwinkel escribió:
Hi Gilles,

First i must say i have not updated to the latest GC so not sure if things are the same with python and treading. I'm running on an older build:
image.png

Hi Remco, I think the problem the OP is reporting is not related to GC build but to Dash version, which Dash version works for you? 

Ale Martinez

unread,
Oct 20, 2023, 1:47:00 PM10/20/23
to golden-cheetah-users
El viernes, 20 de octubre de 2023 a la(s) 11:47:12 UTC-3, gilles....@gmail.com escribió:
When GC points to this installation, the python chart generates the error :
Capture (1).png

Have you checked the code where the error happens?

Mark & Ale : indeed, the dash/python script starts a server... 

My idea is to use dash to implement a user input that represent the name of a segment (combo box selection, or text input) connected to an event which updates the chart of segment's power & duration timeline...

An alternative could be to plot all available segments and use Plotly interactive features to drill down or select the one you are interested. 

Ale Martinez

unread,
Oct 20, 2023, 4:06:50 PM10/20/23
to golden-cheetah-users
I found the failing introspection was added in latest release: https://github.com/plotly/dash/commit/a83c5b3087a2b74de2a0b3cf7b1a67260ae5f97f, your example works using the previous version (dash==2.13.0)

marcen

unread,
Oct 20, 2023, 4:12:15 PM10/20/23
to golden-cheetah-users
Hi Gilles,

I don't know if I understood correctly what you are trying to do.

There is a chart available for selected segment with power, duration and more metrics:
https://groups.google.com/g/golden-cheetah-users/c/7kJ0tCIHnyo/m/D4sTKysCDAAJ

gilles....@gmail.com

unread,
Oct 26, 2023, 9:51:15 AM10/26/23
to golden-cheetah-users
Thank you for your answers !

Ale : I rolled back dash module to previous version " (dash==2.13.0)". Unfortunately, there is some trouble :
- when python interpreter is run from an external console, everything is correct :
>>> import dash
>>> dash.__version__
'2.13.0'
C:\Users\xxx\AppData\Local\Programs\Python\Python37>python.exe c:\gilles\dcc_input_example.py
Dash is running on http://127.0.0.1:8050/

 * Serving Flask app 'dcc_input_example'
 * Debug mode: on

- in GC, dash is not found anymore : "No module named "dash"

marcen : thank you very much for letting me discover "leaderboard.py" python chart ! 
This is almost everything that I wanted.
I've tested it since last monday...

Best regards

Joachim Kohlhammer

unread,
Oct 26, 2023, 5:09:03 PM10/26/23
to golden-cheetah-users
Hi Gilles,

gilles....@gmail.com schrieb am Donnerstag, 26. Oktober 2023 um 15:51:15 UTC+2:

marcen : thank you very much for letting me discover "leaderboard.py" python chart ! 
This is almost everything that I wanted.
I've tested it since last monday...

Nice to hear that you like my script. I have put it in a github repo (https://github.com/thejockl/goldencharts), maybe we can extend it to fully meet your needs - always open for new ideas

Regards
 Joachim
Reply all
Reply to author
Forward
0 new messages