闪亮的数据表:根据两个条件格式化行 [英] Shiny datatable: Format row depending on two conditions

查看:53
本文介绍了闪亮的数据表:根据两个条件格式化行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有这个:

datatable(SignalDataFrame,selection = 'single', options=list(dom='ft')) %>%
    #datatable(ResultDF, options=list(dom='ft')) %>%
      formatStyle(
        '200d MA',
        backgroundColor = styleInterval(0, c('#e6b8b7', '#d8e4bc'))
      ) %>%
      formatStyle(
        '50v200d MA',
        backgroundColor = styleInterval(0, c('#e6b8b7', '#d8e4bc'))
      ) %>%
      formatDate(c(3,5,6), "toLocaleDateString")
    })

如您所见,样式间隔仅以红色格式化< 0值,以绿色格式化> 0值.但是,我只想将红色的单元格格式化为绿色,将其相应的日期小于"十天."

例如,如果该单元格中的值小于0并且第3列中的日期小于10天,则200dMA列(即第2列)应仅显示为红色.如果值> 0并且第3列中的日期小于10天,则应为绿色.

我该如何实现?

解决方案

您可以在SignalDataFrame上添加一个额外的列check,以检查列200d MA50v200d MA.然后,在formatStyle处使用它,并用visible隐藏它.

Currently I have this:

datatable(SignalDataFrame,selection = 'single', options=list(dom='ft')) %>%
    #datatable(ResultDF, options=list(dom='ft')) %>%
      formatStyle(
        '200d MA',
        backgroundColor = styleInterval(0, c('#e6b8b7', '#d8e4bc'))
      ) %>%
      formatStyle(
        '50v200d MA',
        backgroundColor = styleInterval(0, c('#e6b8b7', '#d8e4bc'))
      ) %>%
      formatDate(c(3,5,6), "toLocaleDateString")
    })

As you see, style interval only formats values <0 in red and values >0 in green. I however want only to format cells in red respective in green for which their respective date is "younger" than 10 days.

For example column 200dMA (being column 2) should be only red if the value in this cell is <0 and the date in column 3 is younger than 10 days. And it should be green if the value is >0 and the date in column 3 is younger than 10 days.

How can I achieve that?

解决方案

You could add an extra column check to SignalDataFrame that checks columns 200d MA and 50v200d MA. Than, use it at formatStyle and hide it with visible.

这篇关于闪亮的数据表:根据两个条件格式化行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆