r闪亮的通信柱尺寸在r和javaScript之间,带有殖民地

发布于 2025-01-29 19:33:18 字数 304 浏览 1 评论 0原文

我正在使用 this plugin以启用手动列,以调整手动列,以在DataTables中调整DataTables r闪亮。现在,我想在用户调整表尺寸后保存列宽状态。为此,我想将更改传达成闪亮的输入变量。但是,我对JavaScript和jQuery来说是很新的,这意味着我不了解GitHub页面上的说明。因此,我想问一下如何实现这一目标。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落画卷 2025-02-05 19:33:18
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)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文