Plotting functions (equations) with plotly

Hi fellows plotly users.

I’m looking for a way to trace function directly from its equation.
It can be done with ggplot with the function stat_function.

I can easily compute the function statically, and then plot the result with a scatter plot:


myFunction <- function(x){
    return (a*x+b)

myX <- seq(-25,15,0.1)
myY <-myFunction(myX)

fig <- plot_ly(
    type = 'scatter',
    mode = 'lines',
    x = myX,
    y = myY,
    legendgroup = paste("MyFunction")

htmlwidgets::saveWidget( as_widget(fig), "MWELiveFunction.html");

But this solution is static and I would like to be able to modify on the go the function parameters (a and b) from buttons.

Any ideas on how I could manage to just trace the curve from the function equation ?