Download a separate Markdown file report as html

770 views
Skip to first unread message

YShao

unread,
Apr 15, 2013, 10:41:32 AM4/15/13
to shiny-...@googlegroups.com
Hello, 

I have a Shiny interface that displays my data. 

In the download function, I would like to download a separate report I've compiled using this data from RMarkdown and knitr. 
My current code for the downloadHander in server.R  is this. 

output$downloadData<- downloadHandler(filename ="ShinyData.html", 
                                      content= function(file){
                                      knit2html("myreport.md", file);

                                      }
  )

This successfully creates a myreport.html file in the directory folder from the md file, but does not do anything on the UI side. Help?

Yihui Xie

unread,
Apr 15, 2013, 12:36:34 PM4/15/13
to shiny-...@googlegroups.com
You should probably mention it was cross-posted here:
http://stackoverflow.com/questions/15907535/rshiny-how-to-pass-variable-from-server-r-to-an-rmd-script

I still have not got a chance to look into it. Hopefully other people
can help you.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
> --
> You received this message because you are subscribed to the Google Groups
> "Shiny - Web Framework for R" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shiny-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Winston Chang

unread,
Apr 15, 2013, 3:18:29 PM4/15/13
to shiny-...@googlegroups.com
It would be very helpful for diagnosing the issue if you could supply a reproducible example app (in a gist, for example).

-Winston


On Mon, Apr 15, 2013 at 9:41 AM, YShao <jayce...@gmail.com> wrote:

YShao

unread,
Apr 16, 2013, 9:52:29 AM4/16/13
to shiny-...@googlegroups.com
https://gist.github.com/Shaoy/5396030
 
I am so frustrated that I am pulling out my hair right now and throwing them out the window, Please help. 

Winston Chang

unread,
Apr 16, 2013, 11:59:03 AM4/16/13
to shiny-...@googlegroups.com
The function that's given as the 'content' argument to downloadHandler takes one option, 'file'. When the download button is clicked, the download handler calls that function, and it uses the file argument to tell it where is should save the output file.

I don't see a way to set the output file name from knit2html(), but you can just rename it after it's created:

  output$downloadData <- downloadHandler(
    filename ="ShinyData.html", 
    content = function(file) {
      knit2html("myreport.rmd")
      file.rename("myreport.html", file)
    }
  )



(Also, you're missing a closing parenthesis in ui.r.)

-Winston

YShao

unread,
Apr 16, 2013, 12:24:28 PM4/16/13
to shiny-...@googlegroups.com
Thank you very much.   

I guess I was confused as to what the content part of the downloadHandler really does. 

Wei Zhao

unread,
May 28, 2013, 4:52:37 PM5/28/13
to shiny-...@googlegroups.com
I tried this example but it didn't work on my Shiny server. The error message is  "cannot open the connection"

Wei


On Tuesday, April 16, 2013 11:59:03 AM UTC-4, Winston Chang wrote:
Reply all
Reply to author
Forward
0 new messages