This is my goto article for dynamically updating widgets. I’m sure it could be adopted to your use case.
Personally, I struggle to implement widgets with real time indicator updates. Therefore, I only create real time dashboards, where all the processing is done in the background and the real time dashboard can update at a different rate to the background processor, this way the user does not need to interact with widgets. I also posted a question about real time data processing which might also give you some pointers.