Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“Not Found” error when deploying to shinyapps.io, whereas app deployed well hours ago, and still does locally #1714

Closed
pablobernabeu opened this issue Dec 1, 2019 · 11 comments
Labels
Bug

Comments

@pablobernabeu
Copy link

@pablobernabeu pablobernabeu commented Dec 1, 2019

[UPDATED: Please find comment below]

Hi all,

I would be very grateful if I could receive some help with a 'Not Found' error that I and another user have encountered, only over the last days, when deploying Flexdashboard-Shiny apps to the shinyapps.io server. Would you please find the initial issue on the community.

The error may be reproduced by deploying a Flexdashboard-Shiny (runtime: shiny) app such as this one to the shinyapps.io server.

Since this error has emerged only over the last two days for myself, and I think it's the same for the other user who commented on my Community post, I've tried to spot any relevant, recent releases to CRAN. The RMarkdown package seems to have been updated these days, indeed with changes around Shiny (d4d2a8f). I would be really grateful if someone could test this issue by deploying any Flexdashboard-Shiny app (e.g., from the examples) to the shinyapps.io server.

Cross-posting: rstudio/shiny#2715. I'll take care of updating and closing all posts as soon as the issue has been resolved.

Thank you very much!


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@pablobernabeu

This comment has been minimized.

Copy link
Author

@pablobernabeu pablobernabeu commented Dec 1, 2019

Updated: I tried to deploy my app after installing the previous rmarkdown version,

require(devtools); install_version("rmarkdown", version = "1.17", repos = "http://cran.us.r-project.org")

and the error vanished! 🎆

@cderv

This comment has been minimized.

Copy link
Contributor

@cderv cderv commented Dec 2, 2019

I can confirm this happened in this commit 5bb98e1

When you install from the previous commit then deployed, the app works

devtools::install_github("rstudio/rmarkdown@1e0964cb7a690866699fd10b41f42b32ea7f32b3")

But if you install the faulty commit, you get the error after deploy.

This is a bug in Rmarkdown, but I don't know how shinyapps.io is running the dashboard with rmarkdown::run(...)

Will try to investigate from the changes introduce in #1703 but it will be easier from someone from the shinyapps team I guess.

@pablobernabeu

This comment has been minimized.

Copy link
Author

@pablobernabeu pablobernabeu commented Dec 2, 2019

Thank you for the confirmation!

@everron

This comment has been minimized.

Copy link

@everron everron commented Dec 3, 2019

Hello everyone,

This issue seems to happen not only on shinyapps.io but also on a dockerised flexdashboard.

Here are the steps to reproduce :
I have saved this flexdashboard as test.Rmd and built a docker image using this Dockerfile :

FROM rocker/r-ver:latest

RUN apt-get update \
  && apt-get install -y --no-install-recommends  \
  pandoc \
  && . /etc/environment \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/ \
  && rm -rf /tmp/downloaded_packages/ /tmp/*.rds

RUN install2.r --error \
    -r "https://cran.rstudio.com"\
    flexdashboard \
    shiny \
    && rm -rf /tmp/downloaded_packages/ /tmp/*.rds

COPY . /root

EXPOSE 3838

CMD ["R", "-e", "rmarkdown::run('/root/test.Rmd', shiny_args = list(port = 3838, host = '0.0.0.0'))"]

After saving the Dockerfile and the test.Rmd in the same folder, I am able to build the image using :
docker build -t flextest . and running the container after the build docker run -d -p 3838:3838 flextest

The flexdashboard should be available at http://localhost:3838/ . You will see the "Not Found" error instead.

I can confirm than when installing the previous commit : devtools::install_github("rstudio/rmarkdown@1e0964cb7a690866699fd10b41f42b32ea7f32b3")
(as a new docker image or inside the already existing container), it fixes this problem.

@cderv

This comment has been minimized.

Copy link
Contributor

@cderv cderv commented Dec 3, 2019

Thanks @everron ! This will help a lot for debug. 👍

@aronatkins

This comment has been minimized.

Copy link
Contributor

@aronatkins aronatkins commented Dec 3, 2019

RStudio Connect and shinyapps.io use rmarkdown::run(file = NULL, dir = "...content-location...", ...) when executing R Markdown documents with runtime: shiny.

@aronatkins

This comment has been minimized.

Copy link
Contributor

@aronatkins aronatkins commented Dec 3, 2019

This problem is occurring because we are passing an absolute path to rmarkdown:::rmarkdown_shiny_ui in rmarkdown::run.

rmarkdown/R/shiny.R

Lines 146 to 150 in cf8e5df

app <- shiny::shinyApp(ui = rmarkdown_shiny_ui(dir, default_file),
uiPattern = "^/$|^/index\\.html?$|^(/.*\\.[Rr][Mm][Dd])$",
onStart = onStart,
server = rmarkdown_shiny_server(
dir, default_file, auto_reload, render_args))

When the / path is requested, we use the default file path and then attempt to resolve as a relative path to the application directory.

rmarkdown/R/shiny.R

Lines 315 to 317 in cf8e5df

if (identical(req_path, "/")) {
req_path <- file
}

rmarkdown/R/shiny.R

Lines 327 to 331 in cf8e5df

# document must exist
target_file <- resolve_relative(dir, req_path)
if (is.null(target_file) || !file.exists(target_file)) {
return(NULL)
}

The rmarkdown:::resolve_relative function wants the "file" to be a relative path beneath the directory.

rmarkdown/R/shiny.R

Lines 454 to 470 in cf8e5df

# resolve a path relative to a directory (from Shiny)
resolve_relative <- function(dir, relpath) {
abs.path <- file.path(dir, relpath)
if (!file.exists(abs.path))
return(NULL)
abs.path <- normalize_path(abs.path, mustWork = TRUE)
dir <- normalize_path(dir, mustWork = TRUE)
# trim the possible trailing slash under Windows
if (.Platform$OS.type == 'windows') dir <- sub('/$', '', dir)
if (nchar(abs.path) <= nchar(dir) + 1)
return(NULL)
if (substr(abs.path, 1, nchar(dir)) != dir ||
substr(abs.path, nchar(dir) + 1, nchar(dir) + 1) != '/') {
return(NULL)
}
return(abs.path)
}

@yihui

This comment has been minimized.

Copy link
Member

@yihui yihui commented Dec 3, 2019

Thanks @cderv and @aronatkins! I'll investigate this issue and try to fix it today. Sorry for the trouble!

@aronatkins

This comment has been minimized.

Copy link
Contributor

@aronatkins aronatkins commented Dec 3, 2019

This logic is applied to file but probably should also be applied to default_file:

rmarkdown/R/shiny.R

Lines 106 to 110 in cf8e5df

# compute file path relative to directory (remove common directory prefix
# if it exists)
file_rel <- normalize_path(file)
if (identical(substr(file_rel, 1, nchar(dir)), dir))
file_rel <- substr(file_rel, nchar(dir) + 2, nchar(file_rel))

@yihui yihui added the Bug label Dec 4, 2019
@yihui yihui closed this in 3d648d3 Dec 4, 2019
@yihui

This comment has been minimized.

Copy link
Member

@yihui yihui commented Dec 4, 2019

Should be fixed now. Thank you all!

@pablobernabeu

This comment has been minimized.

Copy link
Author

@pablobernabeu pablobernabeu commented Dec 4, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.