Multiple lines observation in DT

I need to split an observation on a row into multiple lines and still remainig with just only a row.

For example

source<-data.frame("MEASURE"=c("First","First","Second"),"DATE"=c("2017-11-02","2017-12-12","2017-05-15"))
source<-source[source$MEASURE=="First",]
source<-droplevels(source)

Then I get the DATES with levels()

y<-paste(levels(as.factor(cf$DATE)),collapse=",")

And then realize another DF:

s1<-data.frame(matrix(nrow=1, ncol=2))
s1[1,1]<-"Date"
s1[1,2] y

Which gives:

    X1                               X2
1 Date            2017-11-02,2017-12-12

but I need something like this

    X1                               X2
1 Date                       2017-11-02
                             2017-12-12

The words to be splitted could be 1,2 or more. The df is just for summary and it will be used on shiny with DT::renderdataTable()

Anyone can help me?

Upvotes: 0

Views: 1170

Answers (1)

user5029763
user5029763

Reputation: 1933

Using the argument escape might be a solution. You can read about this argument at https://rstudio.github.io/DT/ section 2.9. And substitute the commas for break lines:

library(dplyr)
library(stringr)
s1$X2 %>% str_replace_all(pattern = "[,]", replacement = "<br/>")
datatable(s1, escape = FALSE)

Upvotes: 3

Related Questions