Search code examples
rurlshinymouse-cursor

Set image as cursor in R Shiny


Is there a way to use a web image as cursor when hovering over a button?

I tried something like this:

tags$head(tags$style(HTML(" .custom {  cursor: url(https://c2.staticflickr.com/2/1907/31794847918_04f9e687e1_b.jpg), auto;
} ")))

which has no effect, and I can't find any other examples on the web how to manage this in R shiny.

library(shiny)

ui  <- fluidPage(    
  actionButton(inputId = 'messagebutton', label = 'click me')
)

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

shinyApp(ui = ui, server = server)

Solution

  • This example works for me. I think your image isnt working, but I'm not sure why exactly. It might be too big.

    library(shiny)
    
    csscode <- HTML("
    #messagebutton {  
      cursor: url(http://www.javascriptkit.com/ajax.gif), auto;
    }
    ")
    
    ui  <- fluidPage(    
      tags$head(tags$style(csscode)),
      actionButton(inputId = 'messagebutton', label = 'click me')
    )
    
    server <- function(input, output, session) {}
    
    shinyApp(ui = ui, server = server)