Displayr / flipDimensionReduction

13 stars 6 forks source link

How to render an interactive t-SNE plot web page outside RStudio? #2

Closed imoutsatsos closed 5 years ago

imoutsatsos commented 5 years ago

This is a question on objects created from this package: object of class "c('2Dreduction', 'tSNE')" I have a script that when run inside RStudio renders this object class as a nice interactive plot that I can export as a Web Page and share with others. I was hoping I could do this in a script running outside of RStudio as well.

However, when I tried using the 'htmlwidgets' package to save a 'tSNE_p05' object I get an error as follows:

 htmlwidgets::saveWidget(as.htmlwidget(tSNE_p05), file="C:/CWorkspace/temp/tSNE_p05_widget.html")

Error in UseMethod("as.htmlwidget") : 
  no applicable method for 'as.htmlwidget' applied to an object of class "c('2Dreduction', 'tSNE')"

Is there a recommended way of creating the interactive web page of the t-SNE plot? Any feedback is greatly appreciated.

Best regards Ioannis

chschan commented 5 years ago

Hi Ioannis, tSNE outputs an object containing all the data, but the chart is created by the print function for that object. So you can export the page like this:

data(hbatwithsplits, package = "flipExampleData")
input.data <- hbatwithsplits[, c("x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12")]
res <- DimensionReductionScatterplot(input.data, algorithm = "t-SNE")
chart <- print(res)
htmlwidgets::saveWidget(chart, file = "tSNEplot.html", selfcontained = FALSE)

Let me know if that doesn't work. Cheers, Carmen

imoutsatsos commented 5 years ago

Thank you Carmen. That makes sense! I'm sure to give it a try. Thank you!