Skip to content

Instantly share code, notes, and snippets.

@MayaGans
Created September 24, 2021 01:22
Show Gist options
  • Select an option

  • Save MayaGans/ac4cc3dba52c5f86d62aa9a20d5561c6 to your computer and use it in GitHub Desktop.

Select an option

Save MayaGans/ac4cc3dba52c5f86d62aa9a20d5561c6 to your computer and use it in GitHub Desktop.

Revisions

  1. MayaGans created this gist Sep 24, 2021.
    44 changes: 44 additions & 0 deletions app.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    library(shiny)
    library(DT)

    data <- data.frame(
    a = 1:3,
    b = 2:4,
    c = 5:7
    )

    table <- DT::datatable(
    data,
    filter = "top",
    options = list(
    columnDefs = list(
    list(
    # this class name is also applied to the column title
    # not helpful for d3
    className = 'dt-center',
    targets = 3,
    # by using the render function
    # I can retain the values in column c (5:7)
    # but in order to render a d3 plot
    # we need to append the value to a node
    # d3.select('.dt-center')
    render = DT::JS("function ( data, type, row, meta ) {
    //return d3.select(this).append('svg')
    }")
    )
    )
    )
    )

    ui <- fluidPage(
    tags$head(
    tags$script(src = "d3.js")
    ),
    table
    )

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

    }

    shinyApp(ui, server)
    2 changes: 2 additions & 0 deletions d3.js
    2 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.