JS闪亮的反应表

时间:2021-05-19 08:35:47

标签: javascript r shiny

我有一个表格,当用户单击加号按钮时需要显示该表格。但是这个表是反应性的,它取决于条件。有没有办法实现这一点。我在下面尝试过,但没有成功。

表格在这里是反应性的。所以需要合并到JS里面

library(shiny)
library(DT)
library(shinyjs)



ui <- {
  fluidPage(
    fluidRow(
      column(6,
             dataTableOutput('table1')
      ),
      column(6,
             DTOutput('table2')
      )
    )
  )
}

server <- function(input, output, session) {

  if(3 > 1){
    x = 2
  } else {
    x = 1
  }
  
  table1 <- reactive({
    tags$div(style = "background-color:#cbe6ef;padding:5em",tags$table(tags$thead(tags$tr(tags$th("Number of Reviews",x)))))
  })
  
  output$table1<-
    DT::renderDataTable({
      datatable(cbind(Plus = '&plus;',iris),                      escape = F,
                rownames = F,
                selection = 'none',
                plugins = 'natural',
                extensions = c('Buttons','Responsive'),
                callback = JS("
  table.column(1).nodes().to$().css({cursor: 'pointer'});
                                      var format = function(d) {
                                      return '/table1/';
                                      };
                                      table.on('click', 'td.details-control', function() {
                                      var td = $(this), row = table.row(td.closest('tr'));
                                      if (row.child.isShown()) {
                                      row.child.hide();
                                      td.html('&plus;');
                                      } else {
                                      row.child(format(row.data())).show();
                                      td.html('&minus;');
                                      }
                                      });"
                ))
    })
  
}

options(shiny.launch.browser = TRUE)
shinyApp(ui, server)

0 个答案:

没有答案