我有一个表格,当用户单击加号按钮时需要显示该表格。但是这个表是反应性的,它取决于条件。有没有办法实现这一点。我在下面尝试过,但没有成功。
表格在这里是反应性的。所以需要合并到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 = '+',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('+');
} else {
row.child(format(row.data())).show();
td.html('−');
}
});"
))
})
}
options(shiny.launch.browser = TRUE)
shinyApp(ui, server)