DS4PS / cpp-526-fall-2020

Course shell for CPP 526 Foundations of Data Science I for Fall 2020
http://ds4ps.org/cpp-526-fall-2020/
MIT License
3 stars 1 forks source link

HTML output for Lab 4 #11

Closed jacobtnyoung closed 2 years ago

jacobtnyoung commented 4 years ago

I was not able to figure out how to render an html file from the lab 4 .Rmd file. Right now I have:

output: flexdashboard::flex_dashboard

But, when I change change the output to be html, it does not create a document. That is, the following does not create a .html output file:

output: html_document
jamisoncrawford commented 4 years ago

Hi @jacobtnyoung - yes, apologies for the submission instructions. I updated all assignments with new, boilerplate submission information and did not modify them for this assignment.

You only need to submit your .Rmd file!

jacobtnyoung commented 4 years ago

Thanks! I did notice that the widgets demo renders to html. If there is an extra step there to get it to create an html file, please let me know.

jamisoncrawford commented 4 years ago

Sure thing! Ah, so I believe this is because shinyWidgets allows Shiny in .Rmd files, but because Lab 04 uses the flexdashboard package and syntax, it won't knit in the same way.

I think shinyWidgets has some limitations in terms of storing underlying data in an R Markdown document because, otherwise, I know I'd exclusive use .HTML files shinyWidgets to create all sorts of data products! Being able to email a fully-realized dashboard (or even pseudo-dashboard/report) using R Markdown, with slicers and filters, would be a dream come true.

I typically don't use flex for Shiny apps so this may be better to ask Dr. Lecy!

@lecy could you shed some light on this?

lecy commented 4 years ago

The challenge is that anything that is interactive like widgets requires javascript libraries. The library is added to the folder that appears with the same name as the HTML file.

You need to bundle all of the files for someone to run the HTML page (the flexdashboard is also just an HTML page).

Unlike static HTML pages, if you want to host a dashboard or anything with widgets you need to configure all of the javascript libraries on your server.

This is why you get the runtime option instead of a knitting option when using shiny components in your RMD. It won't automatically save an HTML file for you because they are more complicated to share or host.

image

image

ShinyWidgetsDemo.zip

lecy commented 4 years ago

Try downloading the zipped folder above and opening the HTML file.

I don't think it will load because you need to configure a virtual server to host the local javascript files.

Note that when you run an RMD file with shiny you get a web address that looks like this:

http://127.0.0.1:6803/ShinyWidgetsDemo.Rmd

The numeric IP address is a sign that it is running on a virtual server on your machine.

Again, R Studio is quite sophisticated in that it has abstracted away most of the complexity of these applications so you can focus on development and not worry about all of the details needed to host these files. It works amazingly well given how simple it is to create.

lecy commented 4 years ago

UPDATE: the HTML file actually worked on my machine when the javascript file was bundled!

Not sure if it will work on yours?

If so, that might be an easy solution. Launch the dashboard in your browser, right-click and save the HTML file, then zip the HTML file together with the javascript library. Send that zipped folder instead of the HTML file.

Note that RMD produces HTML complete files. This means all of the elements of the HTML page are embedded in a single document. Typically even simple HTML static pages require an assets folder to run if they have images or other elements.

The HTML complete version converts raw image formats to a weird encoded version. If you open one of your HTML files with a text editor anything that looks like this is actually the code for an image:

format('truetype'),url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiID4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8bWV0YWRhdGE+PC9tZXRhZGF0YT4KPGRlZnM+Cjxmb250IGlkPSJnbHlwaGljb25zX2hhbGZsaW5nc3JlZ3VsYXIiIGhvcml6LWFkdi14PSIxMjAwIiA+Cjxmb250LWZhY2UgdW5pdHMtcGVyLWVtPSIxMjAwIiBhc2NlbnQ9Ijk2MCIgZGVzY2VudD0iLTI0MCIgLz4KPG1pc3NpbmctZ2x5cGggaG9yaXotYWR2LXg9IjUwMCIgLz4KPGdseXBoIGhvcml6LWFkdi14PSIwIiAvPgo8Z2x5cGggaG9yaXotYWR2LXg9IjQwMCIgLz4KPGdseXBoIHVuaWNvZGU9IiAiIC8+CjxnbHlwaCB1bmljb2RlPSIqIiBkPSJNNjAwIDExMDBxMTUgMCAzNCAtMS41dDMwIC0zLjVsMTEgLTFxMTAgLTIgMTcuNSAtMTAuNXQ3LjUgLTE4LjV2LTIyNGwxNTgg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uNXYzNTBoLTM1MHEtMjEgMCAtMzUuNSAxNC41dC0xNC41IDM1LjV2MjAwcTAgMjEgMTQuNSAzNS41dDM1LjUgMTQuNSBoMzUwdjM1MHEwIDIxIDE0LjUgMzUuNXQzNS41IDE0LjV6IiAvPgo8Z2x5cGggdW5pY29kZT0iJiN4YTA7IiAvPgo8Z2x5cGggdW5pY29kZT0iJiN4YTU7IiBkPSJNODI1IDExMDBoMjUwcTEwIDAgMTIuNSAtNXQtNS41IC0xM2wtMzY0IC0zNjRxLTYgLTYgLTExIC0xOGgyNjhxMTAgMCAxMyAtNnQtMyAtMTRsLTEyMCAtMTYwcS02IC04IC0xOCAtMTR0LTIyIC02aC0xMjV2LTEwMGgyNzVxMTAgMCAxMyAtNnQtMyAtMTRsLTEyMCAtMTYwcS02IC04IC0xOCAtMTR0LTIyIC02aC0xMjV2LTE3NHEwIC0xMSAtNy41IC0xOC41dC0xOC41IC03LjVoLTE0OHEtMTEgMCAtMTguNSA3LjV0LTcuNSAxOC41djE3NCBoLTI3NXEtMTAgMCAtMTMgNnQzIDE0bDEyMCAxNjBxNiA4IDE4IDE0dDIyIDZoMTI1djEwMGgtMjc1cS0xMCAwIC0xMyA2dDMgMTRsMTIwIDE2MHE2IDggMTggMTR0MjIgNmgxMThxLTUgMTIgLTExIDE4bC0zNjQgMzY0cS04IDggLTUuNSAxM3QxMi41IDVoMjUwcTI1IDAgNDMgLTE4bDE2NCAtMTY0cTggLTggMTggLTh0MTggOGwxNjQgMTY0cTE4IDE4IDQzIDE4eiIgLz4KPGdseXBoIHVuaWNvZGU9IiYjeDIwMDA7IiBob3Jpei1hZHYteD0iNjUwIiAvPgo8Z2x5cGggdW5pY29kZT0iJiN4MjAwMTsiIGh

That is why you can email a single HTML file without including the assets folder with all of the images stored separately.

That is not true for all RMD html pages. Bookdown, for example, produces regular HTML files, if I recall correctly.

And it is also not true for any of these dynamic / interactive pages, dashboards, or shiny apps.

jacobtnyoung commented 4 years ago

Oh ok. I will check it out. Thanks!

jacobtnyoung commented 4 years ago

It didn't work on mine ("failed to load error"). Let me take a look at your follow up post.

lecy commented 4 years ago

It didn't work on mine ("failed to load error").

I don't know enough about how the javascript libraries operate to conjecture on ways to share files so they will work on different machines, but I do know that anything with javascript is typically hosted on a server.

You get something like 5 free apps with Shinyapps.io. That's the most common way to share interactive documents or shiny apps.