HTML file from server.R to ui.R

1,127 views
Skip to first unread message

Megh shah

unread,
Feb 11, 2013, 3:51:31 PM2/11/13
to shiny-...@googlegroups.com
Hi,
   I have multiple .HTML files created using knitr. I understand that html files can be added to the application using includeHTML("myfile.html") in ui.R file.
I want to do this differently. Based on the users input (for example: a pricing model or stock name) I would like to select a specific file (matching the users input to all the file names), then return the matched file from server.R to ui.R so it gets displayed. I am not being able to return the html file from server.R to ui.R.

Will be very helpful if someone can assist. 

Thank you,

Megh

Ramnath Vaidyanathan

unread,
Feb 11, 2013, 3:56:54 PM2/11/13
to shiny-...@googlegroups.com
Use reactiveUI to achieve what you want. Here is a rough sketch of what to insert in server.R and ui.R. So whenever, the user selects a different model, the reactiveUI will trigger HTML to be included from the appropriate file.

=========
server.R
=========

output$showfile <- reactiveUI(function(){
  file_to_show = switch(input$model, 'file1.html', 'file2.html')
  includeHTML(file_to_show)
})

==========
ui.R
==========

uiOutput("showfile")

Megh shah

unread,
Feb 11, 2013, 4:16:01 PM2/11/13
to shiny-...@googlegroups.com
Hi Ramnath,
                  Thank you very much for replying. I just tried your method. I am still not being able to transfer any html files from server.R to ui.R. It gives an error shown below. Really cannot understand why this would be happening.  These are simple html files which open in the browser very easily and have no java script or anything like that. 

Error: addFileDependency was called at an unexpected time (no cache context found)


Really hoping for some solution.

Megh

On Tuesday, 12 February 2013 02:26:54 UTC+5:30, Ramnath Vaidyanathan wrote:
Use reactiveUI to achieve what you want. Here is a rough sketch of what to insert in server.R and ui.R. So whenever, the user selects a different model, the reactiveUI will trigger HTML to be included from the appropriate file. f

Ramnath Vaidyanathan

unread,
Feb 11, 2013, 4:22:04 PM2/11/13
to shiny-...@googlegroups.com
Can you post a link to your code, so that we can take a closer look at it?

Megh shah

unread,
Feb 11, 2013, 4:36:57 PM2/11/13
to shiny-...@googlegroups.com
Hi Ramnath,
                 The code is running on internal servers.

In server.R I have the following:

 output$showfile <- reactiveUI(function(){
  file_to_show = 'AAPL.html'
  includeHTML(file_to_show)
})

In ui.R I have 

  tabPanel("Result", 
               uiOutput("showfile")),


includeHTML just does not work. Even on the R studio console, when I used includeHTML('AAPL.html'), I get the following error:

Error in dependsOnFile(path) : 
  addFileDependency was called at an unexpected time (no cache context found)

The html file is in the same directory (as the shiny app) so are the .Rmd files which generated the html (it includes price plot and some tables).

Would there be someway to get rid of the cache problem, which may probably solve this. Also dependsOnFile(path) part of the error might suggest that the html file is in some other directory, but they are not, which is even more confusing. I tried this with Hello Shiny/example one from shiny's website with two tabs, the first one as shown on the website and the second as above. But even there I get the same error. 

Are you being able to load html files easily using the above procedure?

Thank you for helping.

Megh

Ramnath Vaidyanathan

unread,
Feb 11, 2013, 4:51:00 PM2/11/13
to shiny-...@googlegroups.com
Use HTML(readLines(file_to_show)) in place of includeHTML

Megh shah

unread,
Feb 11, 2013, 4:59:37 PM2/11/13
to shiny-...@googlegroups.com
Hi Ramnath,
                  It worked!!! Fantastic! Thank you very much for all your time and patience. 

gerg

unread,
Oct 9, 2015, 4:15:35 PM10/9/15
to Shiny - Web Framework for R
Hey Ramnath-

I am trying the same thing, but its not showing up. I am using dashboard. So i am trying to use the uiOutput in dashboard body. But its not showing up.
Am I missing something? Any help will be appreciated.

Thanks
Gerg
Reply all
Reply to author
Forward
0 new messages