从行的不同元素弹出闪亮的应用程序

问题描述 投票:0回答:1

我正在从行的每个单元格中寻找不同的弹出窗口。 Florian 提供了一个例子,位于 闪亮的数据表:在新窗口中弹出有关所选行的数据

我们可以为不同的单元格设置不同的弹出窗口吗?目前它是行级别。例如 mpg 中的某些链接和光盘中的某个链接等... 下面提供了他提供的代码解决方案

mymtcars = head(mtcars)
for_pop_up = 1:6

app <- shinyApp(
  ui = fluidPage(

    DT::dataTableOutput("mydatatable")
  ),


  server =  shinyServer(function(input, output, session) {

    mycars = head(mtcars)
    output$mydatatable = DT::renderDataTable(mycars, selection = 'single',  
                                             rownames = FALSE, options = list(dom = 't'))

    observeEvent(input$mydatatable_rows_selected,
                 {
                   showModal(modalDialog(
                     title = "You have selected a row!",
                     mycars[input$mydatatable_rows_selected,]
                   ))
    })



  })
r shiny dt
1个回答
0
投票

这是一个 JavaScript 方式:

library(shiny)
library(DT)

js <- c(
  "table.on('click', 'tbody td', function() {",
  "  var indices = table.cell(this).index();",
  "  var i = indices.row;",
  "  var j = indices.column;",
  "  Shiny.setInputValue('click', {row: i, column: j}, {priority: 'event'});",
  "});"
)

shinyApp(
  ui = fluidPage(
    br(),
    DTOutput("mydatatable")
  ),
  
  server =  function(input, output, session) {
    mycars <- head(mtcars)
    output$mydatatable <- renderDT({
      datatable(
        mycars, selection = 'single',  
        rownames = FALSE, options = list(dom = 't'),
        callback = JS(js)
      )
    })
    observeEvent(input$click, {
      i <- input$click$row + 1
      j <- input$click$col + 1
      showModal(modalDialog(
        title = "You have clicked on a cell!",
        mycars[i, j]
      ))
    })
  }
)
© www.soinside.com 2019 - 2024. All rights reserved.