0

Within a Shiny app, I'm trying to link multiple plots. To do this, I need to be able to retrieve hover data with something like event_data("plotly_hover"). Although this has worked for me before, today for some reason I've been running into a problem I haven't been able to troubleshoot. When I hover over any plotly object and display the hover event data, this error is returned within the Shiny app:

Warning: Error in cat: argument 1 (type 'list') cannot be handled by 'cat'

In the past, using event_data(...) on a plotly object has worked well for me so I'm left scratching my head about what may be going on. Here is some self-contained sample code:

ui <- fluidPage(
  plotlyOutput("singlePlot"),
  verbatimTextOutput("hoverData")
)

server <- function(input, output, session) {
  output$singlePlot <- renderPlotly({
    p <- plot_ly(x = 1:10, y = 1:10, color = I("red"), marker = list(color = "blue"))
    p
  })

  output$hoverData <- renderText(event_data("plotly_hover"))
}


shinyApp(ui = ui, server = server) 

In theory I should see something like this:

      curveNumber  pointNumber      x      y 
1               0            1      1      4

But I'm left with the error above. Any ideas on what might be going on?

2 Answers 2

0

I think it is because renderText doesn't know how to treat a dataframe, as the name suggests it renders text, nothing else that does not meet the "string" qualification will work probably. Wrapping it in as.character solves your issue too. renderText( as.character(event_data("plotly_hover")))

ui <- fluidPage(
  plotlyOutput("singlePlot"),
  verbatimTextOutput("hoverData")
)

server <- function(input, output, session) {
  output$singlePlot <- renderPlotly({
    p <- plot_ly(x = 1:10, y = 1:10, color = I("red"), marker = list(color = "blue"))
    p
  })

  output$hoverData <- renderText( as.character(event_data("plotly_hover")))
}


shinyApp(ui = ui, server = server) 
Sign up to request clarification or add additional context in comments.

3 Comments

I found out renderPrint() worked well, but I wasn't quite sure why. Thanks for the explanation!
you're welcome, and renderPrint is the better way to go at it here yes. Enjoy the shiny experience! (I'm guessing you are relatively new to it?)
Exactly-- I'm still getting a hang of it. Thanks!
0

Okay-- I found the solution... kind of silly, but using renderPrint() instead of renderText() works seamlessly. Whoops! Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.