【问题标题】:Pass shiny reactive() value into javascript part of DT将闪亮的 reactive() 值传递到 DT 的 javascript 部分
【发布时间】:2017-04-28 12:52:05
【问题描述】:

我想在 DT 库的 options 中将反应值传递给 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
-----------------------------------------------------------------------

具有静态值的表,cutoff = 4.Working.

### 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')

```

具有反应值的表,cutoff = 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");
                                       }')))
    })
```

【问题讨论】:

    标签: javascript r shiny dt flexdashboard


    【解决方案1】:

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

    需要用单引号中的输入值设置行并起作用。

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

    【讨论】:

      猜你喜欢
      • 2016-10-25
      • 2020-09-18
      • 2019-07-28
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 2018-12-03
      • 2018-09-07
      相关资源
      最近更新 更多