How to build embed `callback` function in `.html` file with using rust?

I have .html file, which is generated by crate Plotly, it shows in website like following:

In the file, there is a button. I'm trying to embed a callback function in this file, so that each time the button is clicked, my server will run some functions and return output to the website, then the website update the output and show it.
In Python, there is a package dash, which is specifically used to do this. But this package doesn't implement in Rust for now.
So I imagine I have two paths to do this:

  1. By mimicking the dash package, building a similar but simple crate by myself
  2. Leaning some rust crates like yew, html5ever, and then do it in a rust way.

I'm just going to do some simple stuff in the final, so I'm trying to figure out that between the two paths which one is easier for someone like me being totally new to .html and web programming.

There's an example of how to use yew with plotly in the plotly repo, maybe use this as a starting point?

I don't think the first path is an alternative to the second. Or I don't understand your first path. As stated in the README from the dash repo, dash is build on top of React and Flask. Both are functionally very extensive, highly abstracted and established frameworks for building client-side applications and web servers, respectively. I don't know what you mean by simple exactly, but I wouldn't recommend going down the path of emulating dash with the most basic technologies and building blocks available to you. I'd rather try and find equivalent Rust frameworks to the ones dash relies on, like yew as an alternative to React and Axum or Actix-web as an alternative to Flask. Now your first path would be equal to your second path which is the most feasible way I imagine such a project to unfold.

1 Like

dash implement in Julia too, here is the package. By reading the source code in the package, I found there is only less than 2000 lines code, so I imagine this package would not be that complicated.

Yes, there is two versions of dash, one for open source and one for enterprise:

The enterprise version is much comlicated shown by picture above. If I'm just do some simple stuff, I also need do it in rust crates like yew, so there are accually no two paths, it has only the second path. I get it, thanks very much.

The callback! function looks quite nice. I'm still don't think it's a good idea to aim for building a Dash-like framework in Rust (yet—you can always adjust your goals and aim higher). Dash seems very highly abstracted and I think you can get your desired solution (a button to reload the data for the plot and redraw it) with far less work, simply by learning the basics of a client-side web framework like yew.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.