Yang-Tang / shinyjqui

jQuery UI Interactions and Effects for Shiny
https://yang-tang.github.io/shinyjqui/
Other
273 stars 32 forks source link

Possible to build custom formula with draggable items? #69

Closed emantzo closed 4 years ago

emantzo commented 4 years ago

Hi, I was wondering if I could use this package in shiny to allow the user to define a custom formula based on pre-defined variables (contained eg in an "orderInput")?

Many thanks for your time!

Yang-Tang commented 4 years ago

Yes, I think so, please see the prototype below:

library(shiny)
library(shinyjqui)

ui <- fluidPage(
  orderInput("ops", "Operators", c("~", "+", "*"),
             as_source = T, connect = "formula", 
             item_class = "default"),
  orderInput("var", "Variables", c("x", "y", "z"), 
             as_source = F, connect = "formula", 
             item_class = "primary",
             placeholder = "(blank)"),
  orderInput("formula", "Formula", items = NULL,
             as_source = F, connect = NULL, placeholder = "(build your formula)"),
  verbatimTextOutput("myFormula")
)

server <- function(input, output, session) {
  output$myFormula <- renderPrint({
    paste0(input$formula, collapse = " ")
  })
}

shinyApp(ui, server)
emantzo commented 4 years ago

Awesome-- thanks a million!