我想将响应值传递到DT库选项中的rowCallback中。请参见下面的示例。我在具有闪亮运行时的flexdashboard中使用它。

设定

---
title: "Untitled"
output:
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    horizontal_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(DT)
library(shiny)
library(shinyjs)
```

Column
-----------------------------------------------------------------------


静态值表格,截止值为4。

### Chart A

```{r,eval=T}
output$mtcarsTable1 <- renderDataTable({
      DT::datatable(datasets::mtcars,
      options = list( pageLength = 5,
                      searching= FALSE,
                      lengthChange = FALSE,
                      ordering=FALSE,
                      rowCallback = JS('
            function(nRow, aData, iDisplayIndex, iDisplayIndexFull,cutoff=4) {
                                      // Bold and green cells for conditions
                                      if (parseFloat(aData[10]) >= cutoff)
                                      $("td:eq(4)", nRow).css("font-weight", "bold");
                                       }')))
    })
dataTableOutput('mtcarsTable1')

```


具有无效值的表,截止值= gearvalue(),不起作用。

### Conditional Bold

```{r}
fillCol(flex = c(1, 6),
      radioButtons("gearvalue","Sensitivity to gear column", c("4" = "4", "3" = "3"), inline=T),
    dataTableOutput('mtcarsTable2'),
     width = "100%")
```


```{r,eval=T}
output$mtcarsTable2 <- renderDataTable({
      DT::datatable(datasets::mtcars,
      options = list( pageLength = 5,
                      searching= FALSE,
                      lengthChange = FALSE,
                      ordering=FALSE,
                      rowCallback = JS('
            function(nRow, aData, iDisplayIndex, iDisplayIndexFull,cutoff=gearvalue()) {
                                      // Bold and green cells for conditions
                                      if (parseFloat(aData[10]) >= cutoff)
                                      $("td:eq(4)", nRow).css("font-weight", "bold");
                                       }')))
    })
```

最佳答案

从这里得到答案Passing input$ value to JS() statement in shiny data table

需要用单引号和输入值设置行。

function(nRow, aData, iDisplayIndex, iDisplayIndexFull, cutoff = ',input$gearvalue,')

09-13 03:06