0

I have a running code for a shiny markdown file. The plot i am trying is a 3d plot to be rendered as a shiny markdown document and not as an APP.

The code works but the 3d plot pops up in a new window and does not render it in the html.

Here is a reproducible example.

---
title: "test"
date: "April 16, 2019"
output: html_document
runtime: shiny
---
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(fig.pos = 'H')
library(kableExtra)
library(rgl) # plot3d
library(knitr)
library(shiny)
knit_hooks$set(webgl = hook_webgl, rgl = hook_rgl)

inputPanel(selectInput('x', label = 'x axis:', choices = colnames(mtcars)[1:7], selected = 'mpg'), 
           selectInput('y', label = 'y axis:', choices = colnames(mtcars)[1:7], selected = 'cyl'),
           selectInput('z', label = 'z axis:', choices = colnames(mtcars)[1:7], selected = 'hp'))

renderPlot({
  plot3d(mtcars[, input$x], mtcars[,input$y], mtcars[,input$z],
         size = 4, 
         xlab = paste('Feat. ', input$x, sep = ''), 
         ylab = paste('Feat. ', input$y, sep = ''),
         zlab = paste('Feat. ', input$z, sep = ''), 
         type = 'p', col = rainbow(3)
                      )
  rglwidget()

})


Output

enter image description here

enter image description here

Any clues what i am missing here ?

Many Thanks.

der_radler
  • 549
  • 1
  • 6
  • 17
  • Have you seen this post? https://stackoverflow.com/questions/44100268/how-to-render-scatter3d-inside-shiny-page-instead-of-popup – J_F Apr 16 '19 at 16:57
  • I think you can plot the same thing using plotly, which can get you out of these plot engine issues. – Hao Apr 16 '19 at 19:54
  • @J_F unfortunately i do not want to run it as a shiny app but as a markdown document. – der_radler Apr 17 '19 at 09:38

0 Answers0