ThinkR-open / golem

A Framework for Building Robust Shiny Apps
https://thinkr-open.github.io/golem/
Other
915 stars 133 forks source link

cannot open file 'Documentation/workflow_accordion.html': No such file or directory #890

Closed gabrielburcea closed 2 years ago

gabrielburcea commented 2 years ago

Hello peps,

I cannot add my html into a module.

This is my initial module:

#' mod_workflows_ui
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd 
#'
#' @importFrom shiny NS tagList 
mod_workflows_ui <- function(id){
  ns <- NS(id)
  shiny::tabPanel(
    "Workflows", icon = icon("list"),
    div(
      class = "container",
      shinyLP::jumbotron(
        "Workflows",
        "How to use the Bioinformatics for the Bench apps to access specific datasets and answer biological questions",
        button = FALSE
      ),
      hr(),
      includeHTML("Documentation/workflow_accordion.html"),
      br(),
      br(),
      br()
    )
  )
  tags$footer(
    includeHTML("Documentation/footer.html")
  )

}

#' mod_workflows_server
#'
#' @noRd 
mod_workflows_server <- function(id){
  ns <- session$ns
}

And I add all those modules where I need to, within app_server, dev_2, etc. This is the error I get.

cannot open file 'Documentation/workflow_accordion.html': No such file or directory
Backtrace:
  1. bftb::app_ui()
       at test-golem-recommended.R:2:2
 22. bftb::mod_workflows_ui("workflows_app_1")
 30. htmltools::includeHTML("Documentation/workflow_accordion.html")
 31. base::readLines(path, warn = FALSE, encoding = "UTF-8")
 32. base::file(con, "r")

And this is the reason I get this error:

includeHTML("Documentation/workflow_accordion.html")

but when I uncomment I get my app working without the info captured into workflow_accrodion.html.

Is there a way you can help. I have all my code into bitbucket Entrerprise, thus cannot provide access to it since is private within company I work for.

gabrielburcea commented 2 years ago

I have also tried this

golem::add_html_template("www/workflow_accordion.html")

Error: [ENOENT] Failed to open '/home/kkwf800/bftb/inst/app/www/www/workflow_accordion.html': no such file or directory

ColinFay commented 2 years ago

Hey,

The path you used in includeHTML seems to be incorrect.

Where is the html file located inside your project ?

gabrielburcea commented 2 years ago

it is in theinst/app/www now. I had a Documentation folder just for html but it does not seem to solve the issue. However, I did now take off the www. And now, it outputs the whole path under thetabPanel Workflow . This is what is shown /home/kkwf800/bftb/inst/app/www/footer.html instead of what is in workflow_accordion.html

ColinFay commented 2 years ago

includeHtml() takes the path to your html file, but it's not specific to golem or anything so you have to give this function a path that does exists.

As your html file is in inst/app/www, then you have to specify this path, and you can do it using app_sys("app/www/footer.html").

If you write includeHtml("footer.html"), then R is going to look in the current working directory, instead of inst/app/www.

gabrielburcea commented 2 years ago

Hello @ColinFay,

I have tried all the suggestions you've added above. Is golem structure posing some limitations to Rshiny devel? I even created a www folder outside of inst so that I can see whether I can manage to upload the full app the way I want. And it seems it does not work.

I am giving you access to this project on github but it is for limited time; let me know if you have some issues around access: https://github.com/gabrielburcea/bftb_gt/tree/tutorials_workflow. More specifically the issue is within mod_workflows module

Would you please help?

gabrielburcea commented 2 years ago

Problem solved using the golem modules. Check the answer here:

https://stackoverflow.com/questions/73200364/why-do-i-get-cannot-open-file-documentation-workflow-accordion-html-no-such/73207025#73207025

Yet, it would be nice golem to work with html as it seems this is indeed an issue.

ColinFay commented 2 years ago

Hey,

I'm currently on holidays. Will come with an answer when I'm back to work.

{golem} does work with html & includeHTML(). I've done it a thousand times ;)

ColinFay commented 2 years ago

@gabrielburcea please either leave the GitHub project open or send me a private access, otherwise it would be hard to debug your issue.

In the same spirit, here is an example with "htmlTemplate()" which literally works the same ways as includeHtml() : https://github.com/ColinFay/golemexamples/blob/master/golemhtmltemplate/R/app_ui.R#L13

gabrielburcea commented 2 years ago

@ColinFay I will leave it public for short time. You can use it now. Also, I have solved the issue by using the golem structure of modularisation of the code. and it works fine. Here I explain every thing: https://stackoverflow.com/questions/73200364/why-do-i-get-cannot-open-file-documentation-workflow-accordion-html-no-such/73207025#73207025

ColinFay commented 2 years ago

Here is another example with includeMarkdown() : https://github.com/ColinFay/golemexamples/blob/master/golemwhereamidemo/R/app_ui.R#L23 Which is the same as includeHtml()

gabrielburcea commented 2 years ago

@ColinFay thank you for this. Are you still debugging or is my answer good enough to close the ticket? I am asking because I want to make my repo private again.

ColinFay commented 2 years ago

Thanks for making it public but I won't be able to have a deep dive into this until next week unfortunately :)

I'm currently on my phone so I can't really dive into this.

Can you add me as a collaborator and keep it private? That way I'll be able to have a look whenever I have time.

gabrielburcea commented 2 years ago

@ColinFay - let me know when you are available so that I can make it public?

ColinFay commented 2 years ago

@gabrielburcea why not making me a collaborator (and remove me after)? That would be easier :)

gabrielburcea commented 2 years ago

@ColinFay - done it, is there another way to contacting you? I am learning how to apply data within golem. and there is another app I am struggling for a week to understand how to interact with paths, datasets, txt, yaml. So I believe I need either an example of a complex app that applied golem structure with all these features - setting paths, datasets, txt files and yaml.

ColinFay commented 2 years ago

Hey,

For the contact, I respond to question either here or on SO — debugging via direct messages (email or other) will only benefit you and not other golem users that might stumble upon your issue :)

So, I just clone your repo, here are the two issues with your code : fix-includehtml

  1. The path to the HTML are incorrect

  2. Your module_ui function only returns the footer, that's why you don't see the rest

Here is the correct code :

mod_workflows_ui <- function(id) {
  ns <- NS(id)
  shiny::tabPanel(
    "Workflows",
    icon = icon("list"),
    div(
      class = "container",
      shinyLP::jumbotron(
        "Workflows",
        "How to use the Bioinformatics for the Bench apps to access specific datasets and answer biological questions",
        button = FALSE
      ),
      hr(),
      includeHTML(app_sys("app/www/workflow_accordion.html")),
      br(),
      br(),
      br(),
      tags$footer(
        includeHTML(app_sys("app/www/footer.html"))
      )
    )
  )
}

See my PR for the fix

ColinFay commented 2 years ago

For your other question, you can read the book at https://engineering-shiny.org/

Then, you'll find examples of elements at

https://github.com/ColinFay/golemexamples

gabrielburcea commented 2 years ago

@ColinFay trying the above did not work since the footer should appear on all pages. The above code (it is my fault as I am confusing you) does not give me as an output the footer

However, I have added the few lines of code

      br(),
      br(),
      br(),
      tags$footer(
        includeHTML(app_sys("app/www/footer.html"))
      )
    )
  )

in the app_ui, right after the the tabPanel modules . And it worked nicely.

with regards to another very complex app, in order to make it profitable for other golem users will post them here. I am tempted to create a recording where I will expose every bit of issues with paths, txt files and data after I will get answers from you. thanks for your help.