闪亮的数据表:在新窗口中弹出有关选定行的数据

Fis*_*ane 4 r datatables shiny dt

我有一个闪亮的数据表。当用户选择某一行时,我想在新窗口中显示基于所选行的其他一些数据。我尝试使用 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)
Run Code Online (Sandbox Code Playgroud)

Flo*_*ian 8

您可以使用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,]
                   ))
    })



  })
)
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!