dreamRs / esquisse

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

Add esquisse as a tabPanel in an app? #130

Closed emantzo closed 3 years ago

emantzo commented 3 years ago

Hi I was wondering how it is possible to use Esquisse as a Tabset in an app, like this :

library(shiny)
library(DT)

library(writexl)

ui <- fluidPage(
  titlePanel("CARS"),

  mainPanel(
    tabsetPanel(type = "tabs",
                tabPanel(
                  id = "dataset",
                  tabPanel(
                    "Cars Bank",

                    DT::dataTableOutput("banking.df_data"),
                    br(),

                    actionButton("saveBtn", "Save"),
                    br(),
                    DT::dataTableOutput("updated.df")
                  )
                ),
                tabPanel(
                  esquisserUI(
                    id = "esquisse", 
                    header = FALSE, # dont display gadget title
                    choose_data = FALSE, # dont display button to change data,
                    container = esquisseContainer(height = "700px")
                  )
                )
    )
  )
)

server <- function(input, output) {
  d1 <- data.frame(cars)

  output$banking.df_data <- renderDataTable(
    d1,
    selection = "none", editable = TRUE,
    rownames = TRUE,
    extensions = "Buttons",

    options = list(
      paging = TRUE,
      searching = TRUE,
      fixedColumns = TRUE,
      autoWidth = TRUE,
      ordering = TRUE,
      dom = "Bfrtip",
      buttons = c("csv", "excel")
    ),

    class = "display"
  )

  observeEvent(input$banking.df_data_cell_edit, {
    d1[input$banking.df_data_cell_edit$row, input$banking.df_data_cell_edit$col] <<- input$banking.df_data_cell_edit$value
  })

  observeEvent(input$saveBtn, {

    write_xlsx(d1, "test3.xlsx")

  })

}

shinyApp(ui = ui, server = server)
emantzo commented 3 years ago

seems I had forgotten line: title = "esquisse", before esquisserUI(

Works fine now!