Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
R Shiny communicate column sizes between R and Javascript with colResize

I'm using this plugin to enable manual column resizing for the DataTables in R Shiny. Now I would like to save the column width state after the user resized the table. For this I would like to communicate the change into a Shiny input variable. However I am quite new to Javascript and jQuery which means I don't understand the instructions on the Github page. So I would like to ask how to achieve this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

library(shiny)
library(DT)
library(htmltools)

dep <- htmlDependency(
  name = "colResize", 
  version = "1.6.1", 
  src = normalizePath("colResize"),
  script = "jquery.dataTables.colResize.js",
  stylesheet = "jquery.dataTables.colResize.css",
  all_files = FALSE
)

js <- c(
  "function(column, columns){",
  "  Shiny.setInputValue('colwidth', column);",
  "}"
)

dat <- head(iris, 6)

ui <- fluidPage(
  br(),
  fluidRow(
    column(
      width = 8,
      DTOutput("dtable")
    ),
    column(
      width = 4,
      verbatimTextOutput("columnWidth")
    )
  )
)

server <- function(input, output, session){
  
  output[["dtable"]] <- renderDT({
    dtable <- datatable(
      dat,
      options = list(
        colResize = list(
          onResizeEnd = JS(js)
        )
      )
    ) 
    deps <- dtable[["dependencies"]]
    deps <- c(deps, list(dep))
    dtable[["dependencies"]] <- deps
    dtable
  })
  
  output[["columnWidth"]] <- renderPrint({
    input[["colwidth"]]
  })
  
}

shinyApp(ui, server)

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda