dreamRs / esquisse

RStudio add-in to make plots interactively with ggplot2
https://dreamrs.github.io/esquisse
Other
1.78k stars 229 forks source link

dragulaOpts - supply argument as JS? #260

Closed MayaGans closed 7 months ago

MayaGans commented 11 months ago

Hello! I'm trying to leverage dragulas options.invalid to make it so that the Jan block cannot be dragged, but struggling a bit without an example in the documentation

library(shiny)
library(esquisse)

ui <- fluidPage(
   tags$h2("Demo dragulaInput"),
   dragulaInput(
      inputId = "dad1",
      label = "Default:",
      sourceLabel = "Source",
      targetsLabels = c("Target1", "Target2"),
      selected = list(
         Target1 = "Jan"
      ),
      choices = month.abb,
      width = "100%",
      dragulaOpts = list(
         invalid = 
           " function (el, handle) { return el.getAttribute('data-value') === 'Jan'; }"
      )
   ),
   verbatimTextOutput(outputId = "result1")
)

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

   output$result1 <- renderPrint(str(input$dad1))

}

if (interactive())
   shinyApp(ui = ui, server = server)

I've tried supplying "function (el, handle) { return el.tagName === 'Jan'; }" as a string but that just injects it as a string in the JS object and not a function to be evaluated, and using htmltools::JS doesn't work either (maybe because of this: https://github.com/jeroen/jsonlite/issues/77) . Do you have any tips? Thanks!!

pvictor commented 11 months ago

Hello, There no standard way to pass JavaScript options for Inputs (JS() only works for htmlwidgets). I added an exception in bindings to evaluate moves, accepts and invalid as JavaScript code. Re-install from GitHub and let me know how it works for you.

Victor