Commit 552a5c5e authored by biohentze's avatar biohentze

Prevent warnings issued by new version of plotly when registering events when plot is not visible.

parent 3fdf014a
......@@ -385,6 +385,7 @@ server <- function(input, output, session) {
## Show the plot
output$plot <- renderPlotly({
req(rv$data)
selectedCols <- input$selectedVar
D <- rv$data[rv$currentRows,]
IDs <- rownames(D) # Used to uniquely identify data points
......@@ -399,8 +400,8 @@ server <- function(input, output, session) {
colour = "black") +
coord_cartesian(expand = TRUE)
ggplotly(p, tooltip = "none") %>%
config(p = ., staticPlot = FALSE, doubleClick = "reset+autosize", autosize = TRUE, displayModeBar = TRUE, workspace = TRUE,
sendData = FALSE, displaylogo = FALSE, collaborate = FALSE,
config(p = ., staticPlot = FALSE, doubleClick = "reset+autosize", autosizable = TRUE, displayModeBar = TRUE,
sendData = FALSE, displaylogo = FALSE,
modeBarButtonsToRemove = c("sendDataToCloud", "lasso2d", "select2d", "hoverCompareCartesian")) # Control Plotly's tool bar
}
})
......@@ -408,34 +409,39 @@ server <- function(input, output, session) {
## Interactions with the plot
observe({
req(rv$data)
df <- rv$data
## Get indices of data points in selected area (Box and Lasso Select tool)
brush <- event_data("plotly_selected")
if(!is.null(brush)) {
rv$currentRows <- brush$pointNumber +1
}
## Get indices of data points in zoomed-in/out area
zoom <- event_data("plotly_relayout")
if(!is.null(zoom) ) {
## Take care of cases where range is on one axis only
if (!is.null(zoom[['xaxis.range[0]']])) {
if(!is.null(zoom[['yaxis.range[0]']])) {
rv$currentRows <- which(df[, input$selectedVar[1]] >= zoom[['xaxis.range[0]']] &
df[, input$selectedVar[1]] <= zoom[['xaxis.range[1]']] &
df[, input$selectedVar[2]] >= zoom[['yaxis.range[0]']] &
df[, input$selectedVar[2]] <= zoom[['yaxis.range[1]']], arr.ind = TRUE)
} else {
rv$currentRows <- which(df[, input$selectedVar[1]] >= zoom[['xaxis.range[0]']] &
df[, input$selectedVar[1]] <= zoom[['xaxis.range[1]']] , arr.ind = TRUE)
}
} else if(!is.null(zoom[['yaxis.range[0]']])) {
rv$currentRows <- which(df[, input$selectedVar[2]] >= zoom[['yaxis.range[0]']] &
df[, input$selectedVar[2]] <= zoom[['yaxis.range[1]']] , arr.ind = TRUE)
if(input$menu == "output") { # Ensure we already have a plot
brush <- event_data("plotly_selected")
if(!is.null(brush)) {
rv$currentRows <- brush$pointNumber + 1
}
else {
rv$currentRows <- c(1:nrow(rv$data))
## Get indices of data points in zoomed-in/out area
zoom <- event_data("plotly_relayout")
if(!is.null(zoom) ) {
## Take care of cases where range is on one axis only
if (!is.null(zoom[['xaxis.range[0]']])) {
if(!is.null(zoom[['yaxis.range[0]']])) {
rv$currentRows <- which(df[, input$selectedVar[1]] >= zoom[['xaxis.range[0]']] &
df[, input$selectedVar[1]] <= zoom[['xaxis.range[1]']] &
df[, input$selectedVar[2]] >= zoom[['yaxis.range[0]']] &
df[, input$selectedVar[2]] <= zoom[['yaxis.range[1]']], arr.ind = TRUE)
} else {
rv$currentRows <- which(df[, input$selectedVar[1]] >= zoom[['xaxis.range[0]']] &
df[, input$selectedVar[1]] <= zoom[['xaxis.range[1]']] , arr.ind = TRUE)
}
} else if(!is.null(zoom[['yaxis.range[0]']])) {
rv$currentRows <- which(df[, input$selectedVar[2]] >= zoom[['yaxis.range[0]']] &
df[, input$selectedVar[2]] <= zoom[['yaxis.range[1]']] , arr.ind = TRUE)
}
else {
rv$currentRows <- c(1:nrow(rv$data))
}
}
}
rv$currentRows
......@@ -448,16 +454,20 @@ server <- function(input, output, session) {
})
## Get image(s) associated with selected data point
observe({
click <- event_data("plotly_click")
if(!is.null(click)) {
rv$imgPath1 <- as.character(rv$data[unlist(click$key), input$fileCol1])
rv$imgPath2 <- as.character(rv$data[unlist(click$key), input$fileCol2])
if(input$roiFrame != "") {
rv$selectedFrame <- rv$data[unlist(click$key), input$roiFrame]
}
selectRows(proxy, as.numeric(unlist(click$key))) # Set selected point in table
if(!is.null(input$roiX) && input$roiX != "" && !is.null(input$roiY) && input$roiY != ""){
rv$pixelPosition <- unlist(rv$data[unlist(click$key), c(input$roiX, input$roiY)])
req(rv$data)
req(input$selectedVar)
if(input$menu == "output") { # Ensure we already have a plot
click <- event_data("plotly_click")
if(!is.null(click)) {
rv$imgPath1 <- as.character(rv$data[unlist(click$key), input$fileCol1])
rv$imgPath2 <- as.character(rv$data[unlist(click$key), input$fileCol2])
if(input$roiFrame != "") {
rv$selectedFrame <- rv$data[unlist(click$key), input$roiFrame]
}
selectRows(proxy, as.numeric(unlist(click$key))) # Set selected point in table
if(!is.null(input$roiX) && input$roiX != "" && !is.null(input$roiY) && input$roiY != ""){
rv$pixelPosition <- unlist(rv$data[unlist(click$key), c(input$roiX, input$roiY)])
}
}
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment