trafficonese / widgetframe

Embed htmlwidgets in Responsive iframe.
https://bhaskarvk.github.io/widgetframe/
Other
69 stars 11 forks source link

widgetframe can't find file in rmd #21

Open Kaz272 opened 5 years ago

Kaz272 commented 5 years ago

When assigning an htmlwidget, specifically rpivotTable, to frameWidget the file can't be found when knitting to html. It works when running the chunk in R, but not in the html document. I am not very familiar with html so I was unable to troubleshoot in the html output file.

aetiologicCanada commented 5 years ago

I can replicate. Rather keen to resolve. Suggestions welcome.

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(highcharter)

Column {data-width=650}

Chart A

library(tidyverse)
library(widgetframe)
economics_long2 <- economics_long %>% 
  filter(variable %in% c("pop", "uempmed", "unemploy")) 
testchart <- hchart(economics_long2, "line", hcaes(x = date, y = value01, group = variable))

frameWidget(testchart)
#@ggplot(diamonds)+geom_point(aes(x=carat, y=price))

Column {data-width=350}

Chart B

Chart C

Results in: /rmd_output/1/test_simple_files/figure-html//widgets/widget_unnamed-chunk-1.html?initialWidth=736&childId=htmlwidget-c338dad18dff3c806047&parentTitle=Untitled&parentUrl=http%3A%2F%2F127.0.0.1%3A22144%2Frmd_output%2F1%2F not found

in Chart window 1

aetiologicCanada commented 5 years ago

is the double / after figure‐html part of the problem?

aetiologicCanada commented 5 years ago

This is a duplicate of

https://github.com/bhaskarvk/widgetframe/issues/18

I will consolidate discussion there.

neuwirthe commented 4 years ago

I am experiencing the same problem. Any chance this will be repaired in the near future?

neuwirthe commented 4 years ago

Possibly the double slash is not an issue. When compiling html from Rmd with self_contained: FALSE

and

knitr::opts_chunk$set(widgetframe_widgetsdir = 'my_widgets') Thinks work, and the html file contains

<script type="application/json" data-for="htmlwidget-01785f017e85465384e2">{"x":{"url":"meow_files/figure-html//widgets/widget_chart1.html","options":{"xdomain":"*","allowfullscreen":false,"lazyload":false}},"evals":[],"jsHooks":[]}</script>

So the link contains a double slash and still works.

With self_contained: TRUE

The error is /rmd_output/3/meow_files/figure-html//widgets/widget_chart1.html?initialWidth=605&childId=htmlwidget-68b387fd1ac5fd3e8819&parentTitle=meow&parentUrl=http%3A%2F%2F127.0.0.1%3A40787%2Frmd_output%2F3%2F not found

And the directory mentioned here does not look like a subdirectory of the working directory.

neuwirthe commented 4 years ago

I investigated further and fount the following:

Using the parameters as below creates a working html file, but one needs to keep the directory widgetframe_files.

setting widgetframe_self_contained to TRUE also works, then the widget is created as an html file in the same directory as widgetframe.html.

The strange behavior is that

with

knitr::opts_chunk$set(widgetframe_self_contained = FALSE) # default = FALSE
knitr::opts_chunk$set(widgetframe_isolate_widgets = TRUE) # default = TRUE

and

output: 
  html_document:
    keep_md: TRUE
    self_contained: TRUE

Things work, but when setting

output: 
  html_document:
    keep_md: FALSE
    self_contained: TRUE

things stop to work

Contents of file widgetframe.Rmd

title: "widgetframe"
author: "Erich Neuwirth"
date: "3/3/2020"
output: 
html_document:
    keep_md: TRUE
    self_contained: TRUE
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(widgetframe_self_contained = FALSE) # default = FALSE
knitr::opts_chunk$set(widgetframe_isolate_widgets = TRUE) # default = TRUE
library(leaflet)
library(widgetframe)
l <- leaflet() %>% addTiles() %>% setView(0,0,1)
frameWidget(l, width='90%')
houstonhaynes commented 4 years ago

I think you're confusing whether the page is generated versus whether the iframe is visible when deployed to a site. The original case was that it's ok in local debug but when on a live site the iframe renders a 404. The workaround I'm doing now is to simply "fix" the URL path in the final blogdown-rendered HTML files.

https://h3tech.dev/post/deployment-pt1/

But I'm working my way back through widgetframe, htmlwidgets and knitr to see where the URL assembly is taking place in order to find the root cause of the bad double-slash. Since there's not obvious SLASH IS HERE markup in the .R files I assume it's simply picking up partials and stitching them together from some dependency and not clearing the double-slash before committing it to the iframe src value.