【问题标题】:Display popup modal dialogue /popup onclicking the row in shiny dashboard显示弹出模式对话框/popup onclicking闪亮仪表板中的行
【发布时间】:2018-01-22 06:12:23
【问题描述】:

我有一个数据表,正在我闪亮的仪表板中使用DT:: rendertableOutput 呈现。这些列是ABCD。现在我想在打开 Shiny 应用程序时只显示列 AB 如果我单击显示的数据表上的特定行,我需要弹出一个弹出窗口,在列的同一行中显示数据CD

下面是我的数据框:

> df
   A         B       C      D
   A1        B1      C1     D1
   A2        B2      C2     D2   

条件:

  1. 打开闪亮的应用程序时,仅显示AB 列。
  2. 当点击显示数据的row 1 时,CD 列的row 1 将显示为带有close 按钮的弹出窗口。当显示其他行时,这种情况也会类似地继续。

【问题讨论】:

    标签: r shiny shinydashboard dt


    【解决方案1】:

    让我们尝试将其添加到服务器代码中。本质上,当您选择特定行时,我们会触发一个模式对话框,并显示其余数据。

    require(dplyr)
    
    #Here's our table:
    tbl <- data.frame(A= c('A1','A2'),
               B= c('B1','B2'),
               C = c('C1','C2'),
               D = c('D1','D2'))
    
    #The dt output code
    output$my_table <- renderDataTable({
           datatable(tbl %>% select(A,B),selection='single')
    })
    
    #reactive table based on the selected row 
    tbl_reactive <- reactive({
           tbl[as.numeric(input$my_table_rows_selected[1]),]
    })
    
    #here's the table displayed in our modal
    output$modal_table <- renderDataTable({
          tbl_reactive()
    })
    
     #our modal dialog box
        myModal <- function(failed=FALSE){
           modalDialog(
      dataTableOutput('modal_table'),
             easyClose = TRUE
    
           )
         }
    
    #event to trigger the modal box to appear
     observeEvent(input$my_table_rows_selected,{
    
       showModal(myModal())
    
     })
    

    【讨论】:

    • 感谢您的解决方案!!!该代码部分工作,就像我在开始打开应用程序时只能查看 col A col B 并点击弹出窗口一样。所有这些都完全按照我的意愿工作。但是在弹出窗口中没有 col Ccol D 的数据。我需要调用任何库吗?
    • 谢谢,它工作正常问题是dataTableOutput('modal_table') 中有一个不需要的空间。
    猜你喜欢
    • 1970-01-01
    • 2019-05-11
    • 2015-04-22
    • 2018-05-18
    • 2021-12-14
    • 1970-01-01
    • 2021-09-05
    • 1970-01-01
    • 2018-05-30
    相关资源
    最近更新 更多