ggplotly dhutchison  2020-02-29 18:09
Status: Closed
 

Hi,

Trying to get an interactive plot (heatmap) working, e.g., ggplotly, but it's not happening...

Any thoughts?

Here's what I've tried:
(saveWidget works fine in RStudio)

data<-as.data.frame(labkey.data)

# plot
ggp <- ggplot(data_melt, aes(Condition, Analyte)) +                           
                   geom_tile(aes(fill = value)) +
                   theme(axis.text.x = element_text( 
                   angle = 90, 
                   size=6)) +
                   scale_x_discrete(breaks = data_melt$Condition) 

works but not interactive and doesn't auto-size:

ggsave("${imgout:labkeyl_png}",plot=ggp,device="png")

save to a temp location not the report:

saveWidget(ggplotly(ggp), file = "test.html")

no error, but report doesn't show up:

saveWidget(ggplotly(ggp), file = "test.html")
rawHTML <- paste(readLines("test.html"),collapse="\n") 
# ${htmlout:output}
write(rawHTML, file="output")
 
 
chetc (LabKey Support) responded:  2020-03-02 12:04
Status: Active

Hello,

Thank you for reaching out to us!

Ive been playing around with this for some time and I need some more information from you.

  1. Could you please send the entire source for your report?
  2. When you saved the file to a temp location, did the interactive heatmap work as you wanted?
  3. When using the "saveWidget" did you experience any issues with that function not being found?
  4. Are you using the ggplot2 library? or What packages/libraries are you using?

Thanks,
Chet

 
dhutchison responded:  2020-03-02 13:08

">Could you please send the entire source for your report?"
Sure thing:

library(ggplot2)
library(reshape2)
library(plotly)
library(htmlwidgets)

# this (fix Pandoc error)
Sys.setenv(RSTUDIO_PANDOC='C:/Program Files (x86)/Pandoc')

run<-as.data.frame(labkey.data)
#print(head(run))

data<-run[c(1,50,8:48)]

colnames(data)[colnames(data) == "specimenid"] <- "Name"
#print(dim(data))
#print(reshape2::melt(data$Name))

data<-aggregate(data[c(2:42)], list(data$Name), mean)
rownames(data) <- data$Group.1

data_melt<-reshape2::melt(data)

colnames(data_melt)[colnames(data_melt) == "Group.1"] <- "Condition"
colnames(data_melt)[colnames(data_melt) == "variable"] <- "Analyte"

# Create heatmap with ggplot2
ggp <- ggplot(data_melt, aes(Condition, Analyte)) +                           
              geom_tile(aes(fill = value)) +
               theme(axis.text.x = element_text( 
                   angle = 90, 
                   size=6)) +
             scale_x_discrete(breaks = data_melt$Condition)

# Save ggplotly as widget in file test.html -  fails ... permission?
#saveWidget(ggplotly(ggp), file = paste(labkey.url.base, labkey.url.path, "test.html", sep='')) 

# report doesn't show - now I get "Failed to retrieve report results"
# "output.html" saved to temp and is desired interactive plotly
#saveWidget(ggplotly(ggp), file = "test.html")
#rawHTML <- paste(readLines("test.html"),collapse="\n") 
## ${htmlout:output}
#write(rawHTML, file="output")

# "Failed to retrieve report results" writes "output" in temp location, 
# looks like html, but wont display in browser
#saveWidget(ggplotly(ggp), file = "output")
## ${htmlout:output}
#write(ggplotly(ggp), file="output")

# works, but not auto-sized, not interactive
ggsave("${imgout:labkeyl_png}",plot=ggp,device="png",width=5, height=8)

">When you saved the file to a temp location, did the interactive heatmap work as you wanted?"
yes, when writing raw HTML

">When using the "saveWidget" did you experience any issues with that function not being found?"
No, but there was a Pandoc error. It was in the system path but wasn't being seen by the report/script

">Are you using the ggplot2 library? or What packages/libraries are you using?"
yes, ggplot2

Disclosure: I am on an older version of labkey (18.2) - my next step was to create an installation with the latest LabKey and test it there. But it'd be helpful to know if you think it should work or not.

 
chetc (LabKey Support) responded:  2020-03-03 09:38

Hello,

I am still working out a solution for this, but no I don't think that would be helpful for this issue.

Thanks,
Chet

 
dhutchison responded:  2020-03-10 14:48

Hi Chet,

Any progress? It seems so close to working.

Don

 
chetc (LabKey Support) responded:  2020-03-11 16:40

Hello Don,

Unfortunately not. It does seem very close, there is a plot but it's just not interactive. I tried playing around with some other packages like RMarkdown, leaflet, and webshot but still no luck.

I've asked some of our developers and they are saying its unsupported.

Please let me know if there is anything else I can help you with.

Thanks,
Chet

 
dhutchison responded:  2020-03-13 13:32
Status: Closed

Hi Chet,

That's disappointing ... It would be great to be able to create custom html/js/jquery etc and send it to the report output. Pipeline Pilot does something like this in an output panel making that part at least nicely flexible.

From the forums, it seems shiny is/was supported in LabKey. Do you know if that is still the case?

Thanks,
Don