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

Posted

技术标签:

【中文标题】闪亮的数据表:在新窗口中弹出有关所选行的数据【英文标题】:Shiny datatable: popup data about selected row in a new window 【发布时间】:2017-12-22 09:58:51 【问题描述】:

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

【问题讨论】:

【参考方案1】:

你可以使用一个 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,]
                   ))
    )



  )
)

希望这会有所帮助!

【讨论】:

感谢一百万!这正是我一直在寻找的! 没问题,很高兴能帮上忙。祝你的 Shiny 应用好运!

以上是关于闪亮的数据表:在新窗口中弹出有关所选行的数据的主要内容,如果未能解决你的问题,请参考以下文章