I have created a simple shiny app that is similar to something I am trying to do in a more complex shiny app.
This works fine for the first few highlight / hovers, but then it freezes up. I was having similar behavior in my more complicated app.
Below is the code. Any ideas would be greatly appreciated!
library(plotly) ##Must use devtools::install_github(“ropensci/plotly”)
library(shiny)
shinyUI <- fluidPage(
fluidRow(
column(6, plotlyOutput(“a”)),
column(6, plotlyOutput(“b”)))
)
server <- function(input, output){
data <- reactive({
index <- c(1,2,3,4,5)
var <- c(2,2,2,2,2)
var3 <- c(1,2,3,4,5)
a <- data.frame(index, var3)
index2 <- c(1,2,3,4,5)
var2 <- c(5,4,3,2,1)
b <- data.frame(index2, var2)
colnames(b)[1] <- "index"
a <- SharedData$new(a, ~index, group = "compare")
b <- SharedData$new(b, ~index, group = "compare")
browser()
list(a = a, b = b)
})
output$a <- renderPlotly({
a <- data()$a
p <- plot_ly(data = a, x = ~var3, y = ~var, type = ‘scatter’, mode = ‘markers’,
marker = list(size = 15))
p <- plotly::highlight(p, on = ‘plotly_hover’, persistent = FALSE, opacityDim = getOption(“opacityDim”, .1))
p
})
add chart
output$b <- renderPlotly({
b <- data()$b
p <- plot_ly(data = b, x = ~index, y = ~var2, type = 'scatter', mode = 'markers',
marker = list(size = 15))
p <- plotly::highlight(p, on = 'plotly_hover', persistent = FALSE, opacityDim = getOption("opacityDim", .1))
p
})
}
shinyApp(ui = shinyUI, server = server)