daff icon indicating copy to clipboard operation
daff copied to clipboard

Add htmlwidgets

Open edwindj opened this issue 10 years ago • 11 comments

An htmlwidgets version of daff will allow for data_diff in shiny and rmarkdown.

edwindj avatar Feb 23 '15 13:02 edwindj

How do you want this to look? Do you want it to be like the handsontable implementation on paulfitz.github.io/daff? I think this would be a good start and happy to start putting together.

timelyportfolio avatar Feb 23 '15 14:02 timelyportfolio

The other project I have been experimenting with heavily is https://github.com/benjamine/jsondiffpatch.

timelyportfolio avatar Feb 23 '15 14:02 timelyportfolio

Seems fine to me to start with the implementation of daff (note that render_diff does exactly that). For a later version I may be nice to use bootstrap3 css style, so it integrates nicely with shiny/rmarkdown.

edwindj avatar Feb 23 '15 14:02 edwindj

I was not familiar with this project (https://github.com/benjamine/jsondiffpatch), looks nice!

edwindj avatar Feb 23 '15 14:02 edwindj

Aim of the projects is similar, but jsondiffpatch more focused on non-tabular. What is nice about jsondiffpatch is the built in html renderer, so making a htmlwidget is much easier.

timelyportfolio avatar Feb 23 '15 15:02 timelyportfolio

Just wanted to circle back to this. There are lots of easy improvements without even a full htmlwidget implementation. I think a full implementation would be nice, but for now I'll submit a pull with the simple change. Sorry it has taken me so long.

timelyportfolio avatar Aug 18 '15 18:08 timelyportfolio

Here is the non-htmlwidget implementation https://github.com/timelyportfolio/daff/tree/feature/htmltools using just the helpful htmltools from RStudio. The quick win here is now render_diff will show up in rmarkdown documents, which I demonstrated with this silly vignette.

image

Also, here is an example in Shiny.

library(shiny)
library(daff)

ui <- fluidPage( uiOutput("daff") )

server <- function(input,output,session){
  output$daff <- renderUI({
    y <- iris[1:3,]
    x <- y
    invalidateLater(1000, session)

    x[,1] <- jitter(y[,1])
    patch <- diff_data(y, x)
    render_diff(patch, fragment = F)
  })
}
shinyApp(ui,server)

I would enjoy your thoughts on this. Thanks.

timelyportfolio avatar Aug 19 '15 04:08 timelyportfolio

Hi, is there any progress on this one? I think render_diff is pretty close to the htmlwidget convention, just last mile to wrap in the standard format

happyshows avatar Aug 11 '16 15:08 happyshows

This is excellent work, thank you. Any progress on embedding render_diff output within an rmarkdown document?

dylanbeaudette avatar Sep 18 '17 21:09 dylanbeaudette

Here is my local hack to get daff chunks into rmarkdown HTML documents:

  1. add a "style.css" with a copy of the daff CSS to the YAML header
  2. wrap chunks with this function:
# temp hack to get daff chunks into an rmarkdown doc
wrapDaffHTML <- function(chunkHTML, chunkTitle) {
cat("<div class='highlighter' style='align:center; font-size:80%;'>")
cat(paste0("<h3>", chunkTitle, "</h3>"))
cat(chunkHTML)
cat("</div><br><br>")
}

I am sure there is a better way, but this seems to work OK. It would be nice to get the summary HTML chunks, but I can live without those for now.

dylanbeaudette avatar Sep 19 '17 18:09 dylanbeaudette

Thx for your suggestions! I will work on rendering to markdown next week.

edwindj avatar Sep 20 '17 19:09 edwindj