I have a rowset in a data frame as shown below.
v1 v2 ARSTNFGATTATNMGATGHTGNKGTEEFR SEQUENCE1 BRCTNIGATGATNLGATGHTGNQGTEEFR SEQUENCE2 ARSTNFGATTATNMGATGHTGNKGTEEFR SEQUENCE3
I want to search and highlight some selected substrings inside each row in column v1. For example, assuming that the first letter in a substring looks like "N" and the last letter looks like "G", and the middle letter can be any letter, like in "N A G" or "N B G" or "N C G" or "N D G", etc. To highlight a three-character substring, as shown below, I write 26 lines of code to display on the Shiny R tab, suggesting that there can be any of 26 letters between “ N ” and “ G ”. I'm just trying to optimize the code. I am new to JS. I hope I get it. If not up to the vote down, please let me know if you need more explanation or details.
ARST NFG ATTAT NMG ATGHTG NKG TEEFR
BRCT NIG ATGAT Guilders ATGHTG NQG TEEFR
ARST NFG ATTAT NMG ATGHTG NKG TEEFR
Here is an abbreviated code with representative 2 lines (first and last line) of 26 lines of code used.
datatable(DF, options = list(rowCallback=JS("function(row,data) { data[0] = data[0].replace(/NAG/g,'<span style=\"color:blue; font-weight:bold\">NAG</span>'); ..... data[0] = data[0].replace(/NZG/g, '<span style=\"color:blue; font-weight:bold\"\">NZG</span>'); $('td:eq(0)', row).html(data[0]);}"), dom = 't'))
javascript highlighting r shiny datatables
RanonKahn Nov 19 '16 at 20:34 2016-11-19 20:34
source share