I would like to add the ability to click on imbedded hyperlinks in my floating bar chart created using hc_vistime. Using Hyperlink bar chart in Highcharter, I can activate the link, but it navigates to "file not found". Below is my code.
df1<-data.frame(event=c("store","home","school"),
group=c("john","steve","john"),
start=c(as.POSIXct("2022-9-15"),as.POSIXct("2022-9-16"),as.POSIXct("2022-9-17")),
end=c(as.POSIXct("2022-9-15"),as.POSIXct("2022-9-16"),as.POSIXct("2022-9-17")),
color=c("#D3D3D3","#81ccfe","#D3D3D3"),
url=c("https://www.google.com/","https://www.bing.com/","https://www.msn.com/"))
a<- hc_vistime(df1, optimize_y = T, col.group = "group", show_labels = TRUE)%>%
hc_plotOptions(
series = list(
cursor = "pointer",
point = list(
events = list(
click = JS( "function () { location.href = this.df1$url; }")))))
a
I am confused on how to appropriately link the location.ref command to df1, given the difference in coding structure between vistime and "normal" bar charts.
Thank you in advance.
Related
I am trying to make a map plot using highcharter in which the points can be clicked to access their associated url. I've created the following simplified version of what I am doing (I'm doing a mapbubble plot instead) to illustrate my code. What am I doing wrong? Note: I have also tried this.point.options.url in the javascript section of the code.
library(dplyr)
library(highcharter)
data("USArrests", package = "datasets")
USArrests = mutate(USArrests, "woe-name" = rownames(USArrests))
USArrests[["url"]] = c("https://www.google.com/", "https://www.wikipedia.org/")
hcmap(map = "countries/us/us-all", data = USArrests,
joinBy = "woe-name", value = "UrbanPop", name = "Urban Population",
allowPointSelect = TRUE) %>%
hc_plotOptions(
point = list(
events = list(
click = JS("function() {
window.open(point.url);
}"
)
)
)
)
There are 2 issues with your code:
The map tile is a map and not a point, thus, your option file should link the event handler to map and not point.
To access the urlyou have to use a parameter in your JS function via which you can access the url eventually.
hcmap(map = "countries/us/us-all", data = USArrests,
joinBy = "woe-name", value = "UrbanPop", name = "Urban Population",
allowPointSelect = TRUE) %>%
hc_plotOptions(
map = list(
events = list(
click = JS("function(self) {
window.open(self.point.url);
}"
)
)
)
)
I have developed a dashboard using R and the library shiny, where some different charts are displayed. These ones aren't static charts but they are generated dynamically according to some filters you can set through some bottons and so on.
The next step, what I am working on right now it would be to create a powerpoint report including those charts I have generated before. I got this piece of code so far:
report <- pptx(template = 'report_template.pptx')
report <- addSlide(report,"report_layout")
slide.layouts(report)
slide.layouts(report, "report_layout")
report <- addPlot(report, function() print(p))
writeDoc(report, "example_report.pptx")
Being p a given chart created by plotly this way:
p <- plot_ly(agregado_cedex(), labels = ~Escalado, values = ~Total,type = "pie",
text = ~Total, width = 500, height = 250, hoverinfo = "none") %>% config(displayModeBar = FALSE) %>%
layout(title = "Desglose incidencias", showlegend = TRUE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
There is no problem with this chart as it is correctly displayed on the shiny app (dashboard).
When executing the code above I am getting the next error on R Studio:
Warning: Error in .jcall: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.]
I found something a similar post but it haven't been solved so far Add plots in PPTx without crashing R using addplot()
Does anyone know what is wrong? Thanks in advance!
ReporteRs does not support htmlwidgets. addPlot work with base plot commands, ggplot2, grid and lattice.
I'm trying to set extremes on a time series stock chart that corresponds to a user pushing a button. Here's the breakdown:
User clicks on a button on the top of the chart (I have edited the "All", "1M", "3M" buttons typically at the top)
When the button is clicked, a custom area on the xAxis (2 months) is zoomed in on. For example, October 1st through December first. Right now, the zoom goes to the end of the graph.
It's very similar to the below link.
X Axis Set Extremes
My R code right now for the button is the following:
hc_rangeSelector(buttons=list(list(type='month', text='New', count=2)))
This says I am looking for a month interval zoom, the text is "New", and it shows 2 months. I've seen that setExtremes is the function i'm looking for but I haven't seen it implemented using R.
You could place a JavaScript function in chart.events.load option in Highcharter. Using Renderer you could add a button that will use setExtremes function on click.
Demo in JSFiddle (without Highcharter nor `R, data is different, but functionality of the button is the same): http://jsfiddle.net/e69eLm6q/
Code to run in R:
library("quantmod")
usdjpy <- getSymbols("USD/JPY", src = "oanda", auto.assign = FALSE)
eurkpw <- getSymbols("EUR/KPW", src = "oanda", auto.assign = FALSE)
hc <- highchart(type = "stock") %>%
hc_title(text = "Charting some Symbols") %>%
hc_add_series(data = usdjpy, id = "usdjpy", pointInterval = 36000000) %>%
hc_add_series(data = eurkpw, id = "eurkpw", pointInterval = 36000000) %>%
hc_rangeSelector(buttons=list(list(type='month', text='New', count=2))) %>%
hc_chart(
events = list(
load = JS("function(){
var chart = this;
chart.renderer.button('do stuff',200, 100)
.attr({
zIndex: 3
})
.on('click', function () {
chart.xAxis[0].setExtremes(Date.UTC(1970, 4, 1), Date.UTC(1970, 6, 1));
})
.add();
}")
)
)
hc
How can a popup stay open when clicking on another?
The MWE below show a popup when I click on the markers. Good. But when I click on a second marker I don't want the first popup to disappear. It should only disapear when clicking the close [x]. No popups should be visible before clicking on the markers.
library(leaflet)
the.points <- data.frame(latitude=c(63.136353,63.132935,63.128051),
longitude=c(21.928023,21.962601,21.893444),
text=c("One point", "A second point", "The third point"))
p <- leaflet(the.points)
p <- addTiles(p)
p <- addMarkers(p, lng=~longitude, lat=~latitude, popup=~text)
p
I tried with addPopups too, but they are all visible by default. If that can be changed it would be good (not sure how).
Was struggling with the same thing, finally this worked for me:
leaflet() %>% addTiles() %>%
addMarkers(
lng = -118.456554, lat = 34.085,
popup = "One popup",
popupOptions = popupOptions(autoClose = FALSE, closeOnClick = FALSE)) %>%
addMarkers(
lng = -118.456554, lat = 34.065,
popup = "Another popup",
popupOptions = popupOptions(autoClose = FALSE, closeOnClick = FALSE))
)
I am creating a d3pie graph with rcharts following this article.
I am able to create the pie chart and now I would like to add a tooltip similar to this one.
My code so far is:
require(magrittr)
require(dplyr)
require(rCharts)
df<-data.frame(label=c("group1","group2","group3"),value=c(1,5,4),
stringsAsFactors = FALSE)
pie1<-rCharts$new()
pie1$setLib("http://timelyportfolio.github.io/rChartsExtra/d3pie")
pie1$params$chartspec <- list(header = list(title = list(text = "Title"),
subtitle = list(text = "Subtitle")),
data = list(content = df),
labels = list(lines = list(style = "straight")),
tooltips=list(enabled=TRUE,type= "placeholder",
string="{label}"))
pie1
I am not sure if including the tooltips is possible with rcharts.
If it is possible my guess is that the problem comes from the enabled=TRUE. I also tried: enabled="[true]", enabled="{true}" and enabled=T. None of them seem to work.
I am starting to learn d3.js, however, I want to embed the chart in rmarkdown so I would prefer a solution based on R.