闪亮的数据表:根据两个条件格式化行 [英] Shiny datatable: Format row depending on two conditions
问题描述
目前我有这个:
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 MA
和50v200d 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屋!