Deploy app.R in a server without index.html - r

I'd like to access a Shiny app, app.R via web. In which directory does the app.R need to be stored?
Shiny's default sample apps have their own directories, e.g., /srv/shiny-server/sample-apps/hello. Inside the directory are ui.R and server.R files. The app is linked in index.html with <iframe src="./sample-apps/hello/". I deleted ui.R and server.R files in hello/ directory and place my app.R file there. But I'm now getting error.
Is it possible to run the app without an index.html file? If index.html is must, how do I link the app? I'm perfectly file RStudio's output when app.R is run. No fancy layout is necessary.

For normal webservers: one can't just place the .R file on a server, one actually has to execute it using R. When using a webserver with other content, you can then use proxying (ProxyPass in Apache) to deliver contents, and possibly embed it.
For shiny-server, I'm not sure. It seems to follow the server.R / ui.R pattern. an existing app.R could be refactored like this: ssume you have an app.R with something();shinyApp(ui = verticalLayout(...), server=function(input, output){...}), you could refactor into a server.R with something(); server <- function(input, output){...} and a ui.R with ui <- verficalLayout(...). For the sake of clarity, I put the server / ui assignment on the very bottom of the file.

Related

How to use 'shinytest' with 'golem'?

I'm new to 'golem'. So far I did my Shiny apps as packages, with the app in the folder inst/app, and then to use 'shinytest' I made a folder inst/app/shinytest. How to do with 'golem'? There's no app folder: inst/app only contains www, and the UI and the server are some functions in the package.
So I need to know where to put the 'shinytest' script and how to deal with 'testthat' and the expect_pass function? (I don't want to use testServer)
I've found. It suffices to create a file app.R in the app folder with these contents:
mypackage::run_app()

Shiny Server - Serve only folders with app.R

My shiny-server path has subfolders with files that should not be served. ie, it's like
/srv/shiny-server/
content_folder/
subfolder1/
file_that_should_not_be_served.csv
folder_that_should_not_be_served/
some_files_and_folders
inner_folder/
app.R
supporting_files
I need to serve http://localhost:3838/content_folder/subfolder1/inner_folder/ as shiny application, but need to throw some error (ideally notfound or unauthorized) when other folders/files are opened. eg, http://localhost:3838/content_folder/subfolder1/folder_that_should_not_be_served/ and http://localhost:3838/content_folder/subfolder1/file_that_should_not_be_served.csv should fail.
Is there a way to do this? I'm open to using proxy servers if that would help...

Linking JS file from www subdirectory for R shinydashboard

I have a script.js file in the www subdirectory, which is located in the same directory as my app.R file.
Inside the app.R file, I have something like this:
header <- ...
sidebar <- ...
body <- dashboardBody(tags$head(tags$script(src='script.js')), ...)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) { ... }
shinyApp(ui, server)
But once this is launched in my browser (locally), it says it cannot find the script.js file. Indeed, if I open the Developer Tools in Chrome, I don't see the www subdirectory or anything under the Sources tab.
I thought the www directory should be automatically recognized by Shiny? I'm not sure if it has something to do with this being tested locally (versus published on shinyapps.io?)... or am I missing something here? Thanks in advance!

R Shiny: How to output `getwd()`

Is there something like a working directory when deploying an app to shinyapps.io?
In my app directory I keep ui.r and server.r, as well as another directory for additional scripts (engine). What would be the path to that directory when the app is deployed on shinyapps.io?

Manage paths when deploying R Shiny?

I need some advice on how to take a working app from your local machine onto a web deployment.
I tried deploying an App to Shinyserver.io, but I have path errors. It cannot find my utilities code in utils-fun.R.
Error message
The application failed to start.
Error in eval(expr, envir, enclos) :
could not find function "GetSettings"
For example: my server.R is in an App directory
library(shiny)
code...
source("../code/utils-fun.R")
... rest of code
How do you help RShiny know what it needs to take with when it is deploying?
Should the structure of your directories rather be more like this.
-Root or App directory
ui.R
Server.R
-- code (as subdirectory where my functions are)
-- data (rds and data files)
With everything in one directory, underneath the ui.R /server.R files?
I see from using-source-in-shiny that I need to add local = TRUE to my source but is that all you need?
Thanks I would appreciate any sage advice of how you implement R Shiny.
For tidiness I keep my source files in a folder called "files" alongside ui.r and server.r. Since the working directory for a shiny app is the folder where ui.r and server.r are kept you can use source("files/script.r").

Resources