In plotly, how do you retrieve the camera position of the plot after the user has interacted with it?

Viewed 141

The following code creates an interactive plotly image of biased samples on a surface of a unit sphere. I know I can adjust the initial angle of the camera within layout. Is there a way to get the camera angle after the user has interacted with p_naive? I want to show the camera angle where the user can clearly see the clustering of points at the poles.

library(plotly)
library(dplyr)

n <- 1500
r <- 1

theta_est = runif(n, min = 0, max = pi)
phi_est = runif(n, min = 0, max = 2 * pi)

x_est_naive <- r * sin(theta_est) * cos(phi_est)
y_est_naive <- r * sin(theta_est) * sin(phi_est)
z_est_naive <- r * cos(theta_est)

p_naive <- plot_ly(
  x = x_est_naive,
  y = y_est_naive,
  z = z_est_naive,
  alpha = 0.9,
  type = "scatter3d",
  mode = "markers",
  size = 0.005,
) %>% 
  layout(title = "Naive sampling on Sphere",
         scene = list(camera = list(eye = list(x = 1.25, y = 1, z = 1))))
p_naive
0 Answers
Related