This is not trivial, I found there was a lack of clear examples and I struggled with this... but ultimately I think I have a working example, and I learned some new things that could help me in my own work. 
library(shiny)
library(plotly)
library(isoband)
ui <- fluidPage(
h1("My simple app"),
sliderInput(
inputId = "slider",
label = "Select contour level",
value = 1,
min = 1,
max = 40
),
actionButton(inputId = "btn", "OK"),
plotlyOutput(outputId = "plot")
)
server <- function(input, output, session) {
x <- y <- 0:100
z <- outer(X = x, Y = y, function(x, y) x^0.2 * y^0.6)
# precompute iso levels
iso <- isolines(x = x, y = y, z = z, levels = 1:40)
observeEvent(input$btn,
ignoreInit = TRUE,
{
lvl <- input$slider
mytrace <- list(
type = "scatter3d",
mode = "markers",
x = iso[[lvl]]$x,
y = iso[[lvl]]$y,
z = rep(lvl, length(iso[[lvl]]$id))
)
p1 <- plotlyProxy("plot", session)
plotlyProxyInvoke(p1,
method = "deleteTraces",
list(-1)
)
plotlyProxyInvoke(p1,
method = "addTraces",
list(mytrace)
)
}
)
output$plot <- renderPlotly({
isolate({
lvl <- input$slider
plot_ly(
type = "surface",
x = x,
y = y,
z = z
) %>%
add_trace(
type = "scatter3d",
mode = "markers",
x = iso[[lvl]]$x,
y = iso[[lvl]]$y,
z = lvl
)
})
})
}
shinyApp(ui, server)