Closed reshdesu closed 1 year ago
Do you have an example of how you apply the spinner in flexdashboard
? As far as I know with Rmarkdown (runtime: shiny) you don't have control over the ui
elements, they are automatically created based on the corresponding renderXXX
function (which are in the server
function in Shiny).
When I will have a bit more time I'll try to investigate if this can be circumvented somehow...
I don't know if it is documented anywhere, but you can use the output
variable in a RMarkdown Shiny document. This allows use of the plotOutput
, etc. For example, the renderPlot
portion of the boilerplate RMarkdown Shiny document can be modified to use shinycssloader
as below. This example has a 2 second delay added to renderPlot
so you can see the "Loading..." message (and not the spinner).
output$plot = renderPlot({
Sys.sleep(2) # Make it take some time
hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
xlab = "Duration (minutes)", main = "Geyser eruption duration")
dens <- density(faithful$eruptions, adjust = input$bw_adjust)
lines(dens, col = "blue")
})
shinycssloaders::withSpinner(plotOutput('plot'))
The CSS for the loader doesn't seem to be inserted into the document.
I have added a new branch called rmarkdown
. Installing the package from this branch provides an extra function called rmd_in_header
. This can be used to create a static header file that can be included in an Rmd document.
Limitations are the following:
plotOutput
) in the Rmarkdown file, the i.e. having renderPlot
in the document is not enough (as would be with a simple .Rmd
document, where shiny
does some more magic to create the output function), as the spinner needs to be applied to the output function directly.rmd_in_header
).type
of spinner when generating the header file as you will use in the .Rmd
file when calling withSpinner
. The color
and size
arguments of withSpinner
will have no effect. I will later create a dedicated withSpinnerRmd
function to make this clearer, however wanted to have something working already out there.A working example is given here.
Hi @andrewsali , thank you very much for such a useful library.
I could add shinyccsloaders in my flexdashboard based document. However, I would like to know how to generate a new cssloader_in_header.html
file using the rmd_in_header
function. As you might suppose, I am using thecssloader_in_header.html
example file.
Could you please give me a hint about how to use the rmd_in_header
function?
Regards.
Is this possible to use with flexdashboard? Following from the example you linked, I don't understand how to add it to the yaml when I am not outputting an html_document.
---
title: "Dynamic Model Fit"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
source_code: embed
always_allow_html: yes
---
shinycssloaders does not officially support flexdashboards because they are not shiny apps. It's possible that they might work with some special hacking, if someone here is able to get it to work and post their solution here that would be great, but it might not be possible.
Cool, thank you! I definitely will not be the one to figure that out since I thought a flexdashboard was a shiny app, but hopefully someone else will :)
flexdashboard is rmarkdown. The line between rmarkdown and shiny keeps getting fuzzier with time, but it's still not shiny, sorry :)
Thanks! This explains a lot.
Hi @melissagwolf @daattali . I was able to use it with Flexdashboard. I just did it the same way @andrewsali explained in his example. What is the exact problem you are having?
My yaml looks something like this:
title: "Dynamic Model Fit"
output:
flexdashboard::flex_dashboard:
orientation: columns
includes:
in_header: cssloaders_in_header.html
runtime: shiny
@pernaletec what version of shinycssloaders did you use? The master branch, or the special branch that @andrewsali created?
My main reference was this example: https://github.com/daattali/shinycssloaders/tree/rmarkdown/example/rmarkdown I strictly followed the work of @andrewsali ... thanks BTW!
Thanks for sharing
@pernaletec @daattali Could one of you help me install the version from the special branch? I'm getting a pandoc error without it. Apologies for the entry level question!
I tried this:
library(devtools)
install_github("daattali/shinycssloaders", subdir="rmarkdown")
Downloading GitHub repo daattali/shinycssloaders@master Error: Failed to install 'shinycssloaders' from GitHub: Does not appear to be an R package (no DESCRIPTION)
"rmarkdown" is not a subdirectory, it's a branch. So don't use the "subdir" parameter. I forget what the right parameter is for installing a specific branch, it might be "ref".
Ah. I got it to install, but I had to bypass the update for glue that was requested by the branch (only the binary version is available and my computer won't install it). This causes shinycss to fail when I run @andrewsali 's demo:
pandoc.exe: C:\Users\missg\AppData\Local\Temp\RtmpMBZ78l\cssloaders_in_header.html: openBinaryFile: does not exist (No such file or directory)
Warning: Error in : pandoc document conversion failed with error 1
C'est la vie - I will find another package! Thanks all for your help - I really appreciate it.
Hi, this package and thread is new to me, but after some trial and error I sort of succeeded in my application:
I largely followed @andrewsali instructions, which worked mostly from the beginning. The only two things didn't work well were the spinner was on the very top edge of the container, and my plotlyOutput(height = "100%") was changed to default 400px.
I did the following to correct the two issues: in the cssloaders_in_header.html file, change from: .shiny-spinner-output-container { position: relative; } to: .shiny-spinner-output-container { height: 100%; }
This worked for my narrow-scoped application, but I didn't test for broader situations.
Best, Xiangnan
Thanks! If you think you got it working very well in a robust way, feel free to add a small section to the README telling future people how to do this :)
Hi @daattali , thanks for your comment. I did a one-off trouble-shoot around the existing code, and provided the necessary modifications to make it successfully run in my only application. I'd definitely love to contribute more and do more robust testing. However, the fact that this function is not in the master branch (it's only in the rmarkdown branch last updated three years ago), makes it hard to contribute. Do you have plan to merge the rmarkdown branch to master?
Best, Xiangnan
You're right, I forgot this was all dependent on another branch. I suppose the best solution if we wanted to support Rmd would be to create a separate function and separate files, in the master branch, that would work with rmd. If anybody wants to take on that initiative, I would welcome that.
I just checked, there's no merge conflict between rmarkdown and master branches, do you want me to create a pull request, or it's easier for you to do it. I could take a better look at the rmd_in_header function by @andrewsali and hopefully improve upon.
I'll let you take care of that :) Bring the necessary files in and please do some testing to make sure the regular withSpinner isn't affected
For completion, here is the solution @andrewsali (original author) proposed years ago (I'm copying it here because I want to clean up stale git branches). It includes 3 files:
R/rmd_in_header.R
cssloaders_in_header.html
rmarkdown_example.Rmd
If anyone has a good idea to add rmd support in a clean way, I'd be happy for a PR!
@mkinare @kent37 @pernaletec @xiangnandang @melissagwolf @M-Z @intael @robbfitzsimmons @seabbs @lvalnegri @fawda123 @juliasilge @pernaletec @razielar @MarcoFelipeKing
The latest github version of shinycssloaders should now support rmarkdown. Can you please try it and let me know if it works or not for you. Thanks!
My simple example works.
@mkinare @kent37 @pernaletec @xiangnandang @melissagwolf @M-Z @intael @robbfitzsimmons @seabbs @lvalnegri @fawda123 @juliasilge @pernaletec @razielar @MarcoFelipeKing
The latest github version of shinycssloaders should now support rmarkdown. Can you please try it and let me know if it works or not for you. Thanks!
It works well for me! showPageSpinner()
and hidePageSpinner()
were very easy to implement in my rmarkdown
.
I am using flexidashboard and shinycssloader v0.2.0. When I try to get the loading animation I get the message "Loading..." instead of the animation.