r - Shiny 的数据表 : popup data about selected row in a new window

标签 r datatables shiny dt

我有一个 Shiny 的数据表。当用户选择某一行时,我想在新窗口中显示基于所选行的其他一些数据。我尝试使用 ShinyBS 包,但没有操作按钮我无法使用它,我不想包含操作按钮。我希望在选择一行时显示弹出窗口。有任何想法吗?

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'))

output$popup = renderPrint({
  for_pop_up[input$mydatatable_rows_selected]
  })


 })
)

runApp(app)

最佳答案

您可以使用observeEvent 和模态对话框,如下所示:

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 的数据表 : popup data about selected row in a new window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45151436/

相关文章:

jquery - 从 JavaScript 调用 DataTables 导出函数

R Shiny : passing multiple, 连续 react selectInput

r - 将函数应用于数据框中的所有偶数值

r - ggplot2:用geom_bar绘制平均值

r - 如何按组计算日期之间的时间差

node.js - 在NodeJS中使用带有大量数据的Datatable时搜索错误

javascript - jQuery DataTable 响应式不适用于 Bootstrap 3

css - 使用来自 shinydashboard 的 infoBox 进入 shiny

r - 基于 R 中的 NULL 值的 Shiny 条件面板条件?

r - 如何寻址下一行中的值