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.
Related
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.
I am using the following code semPlot::semPaths to plot a lavaan model (the complete reproducible code is in this Gist).
semPaths(f,
title = FALSE,
curvePivot = TRUE,
what = "std",
rotation = 2,
layout = "tree2",
optimizeLatRes = TRUE,
intercepts = FALSE,
edge.label.cex = 0.95,
exoVar=FALSE,
sizeMan=5,
sizeLat=7,
nCharNodes=5,
residuals=FALSE,
fixedStyle=1,
freeStyle=1,
curvePivot = FALSE)
And the following is the semPaths output:
As you can see, there are weired horizonla lines in the last four manifest variables. How can I remove them? (and why it's happening?)
Thanks in advance!
Update:
This is also the case if saved to PDF (by adding arguments filetype = "pdf", filename = "x") to the function:
I am making multiple dygraphs in a R markdown document. Each dygraph should be in it's own tabset. The code for one of my dygraphs is the following:
# Make a dygraph
dygraph(xts_data, main = "Totaal van nieuwe tickets") %>%
dyRangeSelector() %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyLegend(width = 600) %>%
dyOptions(colors = RColorBrewer::brewer.pal(4, "Dark2")[c(1,3,4)],
fillGraph = TRUE, fillAlpha = 0.4)
This code is properly put within a tabset which is created through the following code:
## Ticket data {.tabset .tabset-fade .tabset-pills}
Now what seems to have is that each time I open a new tab, it doesn't properly display the dygraph. Only when I resize the compiled html document, the graph becomes properly visible again. Has anyone had a similar experience and knows how to solve this?
I'm creating a notebook with shiny and i have found the following issue when using the add-on plotly:
Data_xts=Data_xts() #this return a reactive data.frame. fm_timeseries is already formated as POSIXct and has the following format : YYYY-MM-DD hh:mm:ss
plot_ly(x=Data_xts$fm_timeseries, y = Data_xts$Open,name='Stock Prices',showlegend = FALSE) %>%
add_trace(x=Data_xts$fm_timeseries, y = Data_xts$UKX_open, yaxis='y2') %>%
add_trace(x=Data_xts$fm_timeseries, y = Data_xts$TotalNews, yaxis='y3') %>%
layout(yaxis=list(title='Stock Price'),
yaxis2=list(title='Market Index', overlaying = "y",side='right',position=.97,tickfont = list(size = 8)),
yaxis3=list(title='Total News', overlaying = "y",side='right',anchor='free', tickfont = list(size = 8),position=1),
xaxis=list(title='Time Series') , showlegend = TRUE)
Here is a couple of issues I'm founding:
Time stamp don't show as timestamp (I even tried the simple example from plotly and R and verified that it doesn't work on Shiny). In fact timestamp is categorize as string and the xaxis tittle can't be seen as a result of this.
Challenges getting the yaxis2 and 3 in the same axes without overlapping with the chart itself.
To solve this wonder if there is a format that we can pass into the xaxis (tried type='date' but didn't work) and if there is any type of auto-arrange on the yaxis on the right (2 and 3).
Try using "factor".
So in your example:
plot_ly(x= ~factor(Data_xts$fm_timeseries), y = ~Data_xts$Open, name='Stock Prices',showlegend = 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.