Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wish: support for rgl widget #163

Closed
ugroempi opened this issue Nov 30, 2017 · 5 comments
Closed

Wish: support for rgl widget #163

ugroempi opened this issue Nov 30, 2017 · 5 comments

Comments

@ugroempi
Copy link

Thanks for providing a framework for dashboards! I played with the html widgets example here and tried to replace the MetricsGraphics one with an rgl one:

library(rgl)
plot3d(mtcars$mpg, mtcars$disp, mtcars$hp,
xlab="miles per gallon", ylab="displacement", zlab="horse power", type="s", col=mtcars$cyl)
rglwidget()

This code works in Rmarkdown or bookdown, but does not work within the flexdashboard. I get the error message given below (German machine). It would be nice if rgl could be used in a flexdashboard.

Best, Ulrike

Here is the error message:
"Error in validateCssUnit(sizeInfo$width) : CSS units must be a single-element numeric or character vector"
"Ruft auf: ... -> need_screenshot -> toHTML -> validateCssUnit"

@dmurdoch
Copy link

dmurdoch commented Jan 2, 2018

I've just seen the same error. I'd be happy to modify rglwidget to work with flexdashboard, but I've no idea what modification would be needed. Any suggestions?

@jcheng5
Copy link
Member

jcheng5 commented Jan 2, 2018

@dmurdoch It looks like your widget objects' x$width and x$height are numeric vectors of length 2 (returned from figWidth() and figHeight()), instead of the expected length 1.

@dmurdoch
Copy link

dmurdoch commented Jan 2, 2018

Yes, that's what's causing the problem. It's easy to work around, but I wonder if there's a deeper problem? In the example I was looking at, figHeight() was just rescaling the result of knitr::opts_current$get("fig.height"). That option is allowed to be a vector if you have multiple devices, but in this case the "dev" option is c( "png", "png"), so something looks like a bug.

@dmurdoch
Copy link

dmurdoch commented Jan 2, 2018

I've now put rgl 0.99.5 on R-forge with a fix for this.

@jcheng5
Copy link
Member

jcheng5 commented Jan 3, 2018

Ah, the c("png", "png") appears to be intentional:

if (identical(options$dev, 'png')) {
figure_id <- paste0('fig', next_figure_id)
options$dev <- c('png', 'png')
options$fig.ext <- c('png', 'mb.png')
options$fig.width <- c(options$fig.width, fig_mobile[[1]])
options$fig.height <- c(options$fig.height, fig_mobile[[2]])
options$out.extra <- c(options$out.extra, paste0('data-figure-id=',
figure_id))
options$fig.process <- function(filename) {
if (grepl("^.*\\.mb\\.png$", filename)) {
mobile_figures[[figure_id]] <<- filename
next_figure_id <<- next_figure_id + 1
}
filename
}
}

Looks like it creates one PNG for desktop, and another PNG that's intended for mobile devices in portrait mode. This feature is specific to flexdashboard so it makes sense that this issue doesn't repro elsewhere.

Seems like mystery solved, so I'm closing the issue. Thanks for the report!

@jcheng5 jcheng5 closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants