Я хотел бы иметь возможность сделать что-то вроде ответа на это, но без использования блестящего . Я также хочу связать события onclick, которые открывают гиперссылку, связанную с точкой данных.
Я использую функцию saveWidget
из пакета htmlwidgets
и знаю, что могу вставить код JavaScript с функцией appendContent
из пакета htmltools
.
Вот небольшой пример кода:
library(ggplot2)
library(plotly)
library(htmlwidgets)
library(htmltools)
path.test.results <- "C:\\Users\\img\\"
myData <- data.frame(x=c(1,2,3), y=c(3,2,1))
myLinks <- c("https://www.google.com/", "https://stackoverflow.com/", "https://www.r-project.org/")
ggp <- ggplot(data=myData, aes(x=x, y=y)) + geom_point()
ply <- plotly_build(ggp)
ply$elementId <- "PlotlyGraph"
#javascript <- HTML('<script>document.getElementById("htmlwidget_container").innerHTML = "test";</script>')
javascript <- HTML(paste(
paste('<button type="button" onclick="document.getElementById(',"'", 'PlotlyGraph', "'", ').style.display=',
"'", 'none', "'", '">Hide Plot</button>', sep=''),
paste('<button type="button" onclick="document.getElementById(',"'", 'PlotlyGraph', "'", ').style.display=',
"'", 'block', "'", '">Show Plot</button>', sep='')
,sep=''))
ply <- appendContent(ply, javascript)
saveWidget(widget=ply, file=paste(path.test.results, "test.html", sep=""), selfcontained = FALSE)
dev.off()
Теперь, очевидно, я прошу помощи для правильного кода java-скрипта для сохранения в переменной 'javascript', которую я затем мог бы интегрировать с appendContent в виджет html.