Variable opacity in a scatter 3D plotly plot

How to make a scatter3d look like a density plot in 3d?

I am trying to set the opacity (or some other variable) in a plot_ly scatter3d plot to use a value per point in the plot, with the values coming from a column in the dataframe. This in order to create a sort of 3d scatter density plot. In this case, the opacity column contains random values, but if this turns out to be possible, I want to make points LESS opaque when the amount of nearby points is high, and opaque when they are relatively isolated. Another approach to make this look like a density plot while perserving the scatter3d style is fine as well.

My attempts to play with opacity or alpha in the plot_ly code has failed and I could not find a working example.

The dataset can be downloaded from here: file


mydf <- read.csv("myshowdf.csv")

ui <- fluidPage(
  plotlyOutput('scatter', width = 800, height = 600)  

server <- function(input, output, session) {

  output$scatter <- renderPlotly({
    ppl <- plot_ly(mydf, x = ~FL.Red.Range, y = ~FL.Yellow.Range, z = ~SWS.Length, mode = 'markers',
                   color = ~sub.flow.FP1,   marker = list(size = 4, opacity =mydf$opacity),
                   colors = c('blue', 'green', 'red', 'yellow'),
                   type = 'scatter3d', source = 'scatter') %>%
      layout( autosize = F,
              margin = list(l = 40, r = 20, b = 20, t = 40, pad = 4)
    ppl$elementId <- NULL

shinyApp(ui = ui, server = server)