Markdown in shiny

914 views
Skip to first unread message

Philipp Maier

unread,
Aug 14, 2013, 2:24:16 PM8/14/13
to shiny-...@googlegroups.com
Hi,

I’m having a bit of trouble including Markdown into a shiny application.

Here’s what I’d like to do: I have a text file that contains a data description in markdown. The file can change periodically. I would like to display that contents on top of a chart.

Here’s the snipplet from server.R:

output$Description <- renderText({
x<-readLines(Markdownfile)
return(markdownToHTML(text=x))
})

… and here’s the relevant portion from ui.R:

tabPanel("Overview",
htmlOutput(HTML("GDPDescription")),
plotOutput("ConsensusOverviewChart", height="12in")
),

Alas, no luck. The file contents is displayed, but not rendered as HTML – i.e. I get:

8/13/2013==========================- Test Test Test


So obviously I’m doing something wrong. Any pointers would be appreciated,

Philipp

Vincent Nijs

unread,
Aug 14, 2013, 7:01:28 PM8/14/13
to shiny-...@googlegroups.com
Have you tried the shiny built-in function includeMarkdown ?

Philipp Maier

unread,
Aug 14, 2013, 7:13:29 PM8/14/13
to shiny-...@googlegroups.com
I tried, but couldn't get it to work. My difficulties started when I tried reading in the text file with the markdown code. All I got was "addFileDependency was called at an unexpected time".

Maybe someone has a little "toy shiny page" with markdown that (s)he can share?

Thanks, Philipp

Vincent Nijs

unread,
Aug 14, 2013, 7:31:28 PM8/14/13
to shiny-...@googlegroups.com
I use it in a tabPanel and it works fine:

tabPanel("About", includeMarkdown("about.md"))

Does it work if you use only the markdown in the tabpanel?

Philipp Maier

unread,
Aug 15, 2013, 9:51:12 AM8/15/13
to shiny-...@googlegroups.com
Thanks for your help so far. Here's what I'm struggling with.

If I include an includeMarkdown statement in the ui.R file and hard code the file path, it works. However, my file path can change. So I tried to pass a file name from the server.R file to ui.R, and I'm just not sure how to do this.

Suppose, the variable file.name contains my file name. How do I get this to ui.R? I tried things such as:

output$name <- renderText(file.name), but all I get is "Error: Need input from either a file or text string". I tried:
output$contents <- renderTest({
paste(readLines(file.name), collapse="\n")
})

I get: Error in dependsOnFile(path): addFileDependency was called at an unexpected time

... and now I'm stuck :-(

Any pointers how to fix this would be great!

Thanks, Philipp

Vincent Nijs

unread,
Aug 15, 2013, 12:13:19 PM8/15/13
to shiny-...@googlegroups.com
For dynamics in your UI you can use renderUI

In server.R you have something like:

output$somename <- renderUI({
   includeMarkdown(input$file.name)
})

Then in ui.R include:

uiOutput("some.name")

Philipp Maier

unread,
Aug 15, 2013, 1:50:23 PM8/15/13
to shiny-...@googlegroups.com
Vincent,

I tried. And I'm back to this error:

addFileDependency was called at an unexpected time

Any other ideas?

Many thanks, Philipp

Vincent Nijs

unread,
Aug 15, 2013, 8:50:34 PM8/15/13
to shiny-...@googlegroups.com
Create a minimal code example (working) that demonstrates the problem and share it here. Maybe some can help.
Reply all
Reply to author
Forward
0 new messages