use devtools imported packages in a shiny app - r

I am developing a page with devtools and using DESCRIPTION imports to load appropriate packages. I also added a Shiny app to my package structure (according to the article), so it looks as the following:
- mypacakge
|- inst
|- shiny-examples
|- myapp
|- ui.R
|- server.R
|- R
|- runExample.R
|- ...
|- DESCRIPTION
|- ...
Now, the shiny app works when I add the library instructions at the top of the ui/server files. Is there any way to not paste these instructions, but simply use the DESCRIPTION imported packages? And also, is there any way to make shiny app see package functions from in R folder without running devtools::load_all in Shiny?

Related

Create Package from folder structure with subpackages

I have been given a folder called PackageName with the following structure.
PackageName/
|- SubPackage.jl/
|- src/
|- MyModule.jl
|- test/
|- runtests.jl
|- Project.toml
|- Manifest.toml
|- Project.toml
|- Manifest.toml
|- .gitignore
|- .gitattributes
|- README.md
Inside PackageName there are various .git files like .gitignore, .gitattributes and README.md. There are also a Project.toml and a Manifest.toml which are required in a Julia package. Finally, there are various folders with the structure of SubPackage. Essentially they also contain a Project.toml and a Manifest.toml. They also contain a src/ directory with a Module named MyModule.jl and a test/ directory with some unit testing. The MyModule.jl has a function called myfunction(), which is exported.
I would like to use all the SubPackage-style packages but I am encountering some issues. PackageName doesn't seem to be a proper Julia package because
it doesn't have a src/ directory.
it's Project.toml has an author, a version and [deps] fields but lacks a name and uuid.
What is the best way to go about using the packages in this folder properly within a Julia environment? Essentially I would like to be able to do using PackageName and being able to use myfunction().

Run unit tests with testthat without package

I have a shiny application which uses like 4 functions. I would like to test these functions but it's not a package. How am i supposed to structure my code ? and execute these tests without devtools ?
You can execute tests with testthat::test_dir() or testthat::test_file(). Neither relies on the code being in a package, or using devtools, just the testthat package.
There are few requirements on how to structure your code.
If it were me, I would create a tests directory and add my test scripts under there, which would look something like:
|- my_shiny_app
| |- app.R
| |- tests
| |- test_foo.R
| |- test_bar.R
Then you can run your tests with test_dir('tests'), assuming you're in the my_shiny_app directory.
Your test scripts will have they same structure they have for packages but you'd replace the library() call with source() referencing the file where your functions are defined.
If you have few functions without a package structure, it is better to write single test files manually (so with some simple if/error catching system) that you call with Rscript test_file1.R.
If you start to use the package format instead (which would be advisable for further 'safe' developing) and you still do not want to use testthat, I advise you to follow this blog post: here

How to organize Rmarkdown files (with Shiny runtime) inside a package

Currently I have an analysis project which I treated as package.
So currently I have the following structure:
mycoolanalysispackage/
|-- .Rbuildignore
|-- .gitignore
|-- DESCRIPTION
|-- NAMESPACE
|-- inst
|-- vignettes
|-- R
`-- mycoolanalysispackage.Rproj
At the end I usually produce many Shiny applications as Rmarkdown-flexdashboard file with Shiny runtime.
-- app1/
|-- index.Rmd
-- app2/
|-- index.Rmd
My question is, in which package subdirectory should I put those application directories (along with their index.Rmd files)?
I also have local Shiny Server, what's the best way to link that Rmarkdown-flexdashboard app to that server?
As with everything else, you place them in a subfolder of the inst folder when developing the package. When the package is installed, all folders in the inst folder will be moved to the package folder, and hence can be used as subfolders. So
mycoolanalysispackage/
|-- .Rbuildignore
|-- .gitignore
|-- DESCRIPTION
|-- NAMESPACE
|-- inst
|-- app1/
|-- index.Rmd
|-- etc...
|-- R
`-- mycoolanalysispackage.Rproj
To access the files from within an R function, you can use system.file:
system.file("app1","index.Rmd",package = "mycoolanalysispackage")
will give you the exact path to the index.Rmd of app1. That result can then be used to deploy the app using the appropriate functions.
See also the manual Writing R Extensions (scroll down a bit)

How to create Meteor.js App from barebone sample without "meteor create myApp"?

I have a barebone meteor app with nice folder structure:
Like:
myApp
|- .meteor
|- public
|- img
|- client
|- css
|- view
|- js
|- server
|- helper
|- collection
|- lib
I do not want to say :
meteor create myNewApp
So I copied the myApp -> myNewApp with:
cp -rf * /myNewApp/*
And then i tried to run the meteor app:
cd myNewApp/
meteor run
I get:
run: You're not in a Meteor project directory.
To create a new Meteor project:
meteor create
For example:
meteor create myapp
Is there a way to do this?
#EDIT: I've also tried meteor reset
reset: You're not in a Meteor project directory.
To create a new Meteor project:
meteor create <project name>
For example:
meteor create myapp
Theres also a hidden directory called .meteor that you would need to copy. If you're creating a sort of base structure make sure it has no mongodb database (you can use meteor reset to clear it out).
Running meteor will create the mongodb database for that instance of your app.
This works on all platforms:
meteor create example1
Copy the fresh app:
Then make all the edits you want in there
mkdir newdirectory
cp -r example1 newdirectory
OR
mkdir copyofapp
cp -r example1/. copyofapp
It will make a copy of it in newdirectory. If you have the convenience of a GUI you can also copy and paste the directory example1 using the normal copy+paste. You can then rename the directory whatever you want for the new app
Using cp -r with a wildcard (*) will not copy the hidden files.
In order to find out which files are needed, simply checkout a Meteor application from GitHub.
Cloning a repository is not much different from copying the file structure.
If you look in the examples folder for Meteor you will see two files packages and release. That's all which is needed.

Editing CSS in Gwt WindowBuilder

I am using GWT in a project and recently started using the WindowBuilder in Eclipse. I created a new class and in the WindowBuilder and added some widgets. All that works and everything. However, when I try to edit the CSS for some of the panels and I click to edit the "styleName" field I get an error message which says:
"There are no CSS files referenced from modules HTML."
I've tried adding a link to a style sheet in my base html file and in the Web.gwt.xml file, but that does not seem to work. I get the same error.
In other classes I have used UiBinder and added the style in the XML file, but this class doesn't use UiBinder. So how do I associate a CSS file with the class so that the WindowBuilder allows me to edit the style?
In this project I don't have or use a "war" directory. The project is a couchapp, so I compile it to another directory and push it to CouchDB from there. It seems that in other projects, where there is the original project setup with a war directory, this feature works properly.
I had the same problem and was able to work around it by moving my CSS-resources from the war-directory to the classpath, specifically inside a package that is declared as a "public path" inside the GWT module descriptior via "<public path='...' />".
Project layout (odd location for module descriptor because of Eclipse Plugin Bug):
src
|- main
|- java
| |- demo
| |- client
| | |- MyWidget.java
| | |- MyWidget.ui.xml
| |- Demo.gwt.xml
|- resources
|- demo
|- css
|- Demo.css
Demo.gwt.xml:
<module>
...
<source path="client" />
...
<public path="css" />
<stylesheet src="Demo.css" />
...
</module>
To fix this problem:
In module file gwt.xml type:
<stylesheet src="example.css"/>
Next in menu: Project -> clean.

Resources