How to use 'shinytest' with 'golem'? - r

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()

Related

Why cannot I call the app when I save the R script as app.R into the working directory?

First of all I set my working directory as following
setwd("C:/Users/asus/Desktop/App-1")
Then I can call the app with the following code:
runApp("C:/Users/asus/Desktop/App-1")
But I cannot call the app via :
runApp("App-1")
The script in the directory is named as "app.R" but it appears in the directory as "app".
Whereas, in the R webpage it says if I create a new directory named App-1 it should have worked. But It does not. Many thanks.

The output directory is under your source tree in meteor

how do I solve this
The output directory is under your source tree
warning:the output directory is under your source tree
your generated files may get interpreted as source code
consider building into a different directory instead meteor build ../output
I apologize for my ignorance on this matter, I am new in the world of programming and meteor. about my case. 1. I have a folder on Desk called “Findme” where I have the structure of my project (the code and everything which forms the application which works) 2. Then through the console I access that directory findme and then run the command meteor build/Desktop/MyApp --server = https: //findme.com, and start downloading. 3. But inside the console I also get the message indicated before and when it is finished, and I check the folder MyApp, it is empty. 4. And when I check the Findme folder it has created a folder named ~ and inside displays a file called Desktop/MyApp but it also doesn’t have any useful files, only winrar and nothing useful. 5. I am trying to generate the apk, could you please let me know what I might be doing wrong? Is there another way to generate the apk? I would appreciate it if you could help me!
Your should specify a path for where to build your application that is outside of your project directory.
Otherwise this can lead to problems with Meteor's file watcher and as your error already pointed out:
your generated files may get interpreted as source code consider
building into a different directory instead
So if your command uses a relative path, as used in meteor build ../output then it is important to call this command at the most upper project folder.
Consider the following project structure:
/myapp
/client
/import
/server
If you call meteor build ../output from within /myapp it will generate the output folder as expected outside of the project:
/output
/myapp
/client
/import
/server
However if you call it from within a subfolder, say /myapp/imports it may generate the output within the project like so:
/myapp
/client
/import
/output
/server
So keep this in mind when building your app.
Further readings:
https://guide.meteor.com/deployment.html#custom-deployment
https://docs.meteor.com/commandline.html#meteorbuild

R shiny: Retrieve home directory of a shiny app

Is there a function or a way to retrieve the path of root home directory of a shiny app?
The shiny app I run creates multiple directories and changes working directory. But at point in the app, I need to jump to the home directory. getwd() won't work unless I run it first and save it as a variable or something.
I am thinking of something like the below command used to read a file from a package home directory on any platform without knowing the actual path.
#get root dir
system.file()
# read a file from the root dir of a package
a <- system.file("bla",package="foo")
The approach has to work locally, on shiny-server and shinyapps.io. (In situations where I cannot set the path manually).

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").

Add existing scripts to an Rstudio project

I'm working in Rstudio and have multiple scripts open that have different working directories; however, each working directory exists within a larger folder on my computer (see below). Is it possible to add these scripts to an Rstudio Project without reorganizing all my files and changing each script's working directory?
File structure on computer:
Folder A
~~Folder 1
~~Folder 2
~~Folder 3
Say I have 3 scripts open, each with a working directory of either Folder 1, 2, or 3. Can I create a project that incorporates all three scripts. Say, set working directory to "Folder A"
Thanks much.
Technically, you can change working directory programmatically within a project, but this is considered a very poor practice and is strongly recommended against. However, you can set working directory at a project's top level (full path to Folder A, in your example) and then refer to scripts and objects, located in Folders 1-3 via corresponding relative paths. For example: "./Folder1/MyScript.R" or "./Folder2/MyData.csv".
It should be possible to create a project in the larger folder. You could even construct a simple master script in Folder A to manage this workflow:
setwd("./Folder 1")
source("scriptx")
setwd("..")
setwd("./Folder 2")
source("scripty")
setwd("..")
setwd("./Folder 3")
source("scriptz")
setwd("..")
Compared to source("Folder 1/scriptx") which runs each script within Folder A the master script would be running each script within it's own folder. Just make sure to use setwd("..") after running code in each folder and you can even run code in between to save output to the main Folder A.
If your workflow always creates folders in this manner I don't see how this would not be reproducible if you used relative paths. Albeit platform dependent, this modified version would create folders on the fly and run scripts kept in Folder A.
system("mkdir Folder_1")
setwd("./Folder_1")
source("../Folder A/scriptx")
setwd("..")
Notice here that when running terminal commands in R, it is recommended avoid spaces in directory or file names.

Resources