Shiny datatable: Format row depending on two conditions

假装没事ソ 提交于 2020-03-01 23:14:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32824055/shiny-datatable-format-row-depending-on-two-conditions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!