我的shiny应用程序只有一张桌子(我用的是reactable).

它必须允许多个 Select (以下载选定的行)、触发模式窗口的Click事件(与所单击的行是否被选中无关)以及最后一列上的DoubleClick事件.

我的工作示例执行以下操作:

  1. 允许多个 Select 和下载,
  2. 单击行时的模式(列‘.select’除外) 但是(3)DoubleClick事件不起作用.

下面是DoubleClick事件独立工作的另一个示例.

在第一个示例中,我如何才能使DoubleClick事件工作呢?

(第一个工作示例)

library(shiny)
library(tidyverse)
library(reactable)

ui <- fluidPage(
  downloadButton("dload", "Download (*.csv)"),
  fluidRow(
    column(12, align = 'center',reactableOutput("tbl"))
  )
)
server <- function(input, output, session) {
  
  data = reactive({mtcars %>% tibble::rownames_to_column('car')})
  
  output$tbl = renderReactable(
    reactable(
      data(),
      columns = list(
        carb = colDef(
          sticky = "right",
          sortable = FALSE,
          cell = function(value, index, name){
            icon("globe",
                 ondblclick = sprintf("window.alert('double clicked cell %s in column %s')", index, name)
            )
          })
      ),
      selection = "multiple",
      compact = T,
      highlight = T,
      onClick = JS("function(rowInfo, colInfo, column) {
        Shiny.setInputValue('qwert', {id:rowInfo.id, nonce:Math.random()})
        if (column.id !== 'carb') {
          return
        }
                    }"),
      rowStyle = list(cursor = "pointer")
    )
  )
  
  observeEvent(input$qwert, {
    print(input$qwert)
    id <- input$qwert$id
    row_nr <- as.numeric(id)+1
    showModal(
      modalDialog(
        size = 'l',
        easyClose = T,
        title = data()$car[row_nr],
        "some text"
      )
    )
  })
  
  sel = reactive({getReactableState("tbl","selected")})

  output$dload <- downloadHandler(
    filename = function() {
      paste("d"," ", Sys.time(), ".csv", sep = "")
    },
    content = function(file) {
     write.csv(data()[sel(),],file)# write.csv(dd(), file, row.names = FALSE)
    }
  )
}
shinyApp(ui = ui, server = server)

(我的第二个工作示例--DoubleClick事件)

library(shiny)
library(reactable)

ui <- fillPage(
reactableOutput("t")
)

server <- function(input, output) {

data <- cbind(
  MASS::Cars93[1:5, c("Manufacturer", "Model", "Type", "Price")],
  d = NA
)

output$t <- renderReactable({
reactable(
  data,
  selection = "multiple",
  columns = list(
    d = colDef(
      sortable = FALSE,
      cell = function(value, index, name){
        icon("globe", class = "cor", style = "font-size: 14px;",
            ondblclick = sprintf("window.alert('double clicked cell %s in column %s')", index, name)
    )
  })
)
)})

}
shinyApp(ui,server)

推荐答案

您可以将第一个示例中的JS替换为

function(rowInfo, colInfo, column) {
    if (colInfo.id !== 'carb') {
        Shiny.setInputValue('qwert', {id:rowInfo.id, nonce:Math.random()});
    }
}

然后,双击事件将对最后一列起作用.

enter image description here

Javascript相关问答推荐

使用脚本标签时的JSDoc智能感知

setFinder关闭模式并重定向到url

获取POS餐厅会话用户/收银员

TypScript:根据共享属性对项目进行分组并为其分配groupID

输入有关HTML复选框的已判断属性的信息

Cookie中未保存会话数据

类型自定义lazy Promise. all

如何找出摆线表面上y与x相交的地方?

D3 Scale在v6中工作,但在v7中不工作

嵌套异步JavaScript(微任务和macrotask队列)

在服务器上放置了Create Reaction App Build之后的空白页面

PDF工具包阿拉伯字体的反转数字

Vaadin定制组件-保持对javascrip变量的访问

Phaser3 preFX addGlow不支持zoom

Next.js无法从外部本地主机获取图像

Reaction即使在重新呈现后也会在方法内部保留局部值

本地损坏的Java脚本

react 路由如何使用从加载器返回的数据

将Singleton实例设置为未定义后的Angular 变量引用持久性行为

未捕获的不变违规:即使在使用DndProvider之后也应使用拖放上下文