Shiny: Difference between revisions
Line 153: | Line 153: | ||
* https://github.com/keberwein/docker_shiny-server_centos7 (Shiny + RStudio servers) | * https://github.com/keberwein/docker_shiny-server_centos7 (Shiny + RStudio servers) | ||
= [http://rstudio.github.io/shinydashboard/ | = [https://cran.r-project.org/web/packages/shinydashboard/index.html shinydashboard] = | ||
* http://rstudio.github.io/shinydashboard/ | |||
* [https://www.rstudio.com/resources/videos/dashboards-made-easy/ Dashboards made easy] | * [https://www.rstudio.com/resources/videos/dashboards-made-easy/ Dashboards made easy] | ||
* [https://rviews.rstudio.com/2017/11/15/shiny-and-scheduled-data-r/ Using Shiny with Scheduled and Streaming Data] | * [https://rviews.rstudio.com/2017/11/15/shiny-and-scheduled-data-r/ Using Shiny with Scheduled and Streaming Data] | ||
= [https://cran.rstudio.com/web/packages/flexdashboard/ flexdashboard] = | |||
* The output can be a static HTML file or a dynamic HTML (shiny document) | |||
* https://rmarkdown.rstudio.com/flexdashboard/ | |||
* [https://www.rstudio.com/resources/webinars/introducing-flexdashboards/ Introducing flexdashboards]. The gauge component is cool. | |||
= shinytheme = | = shinytheme = |
Revision as of 10:46, 21 May 2018
Preliminary
The following is what we see on a browser after we run an example from shiny package. See http://rstudio.github.com/shiny/tutorial/#hello-shiny. Note that the R session needs to be on; i.e. R command prompt will not be returned unless we press Ctrl+C or ESC.
More shiny examples can be found on https://github.com/rstudio/shiny-examples shiny-examples.
shiny depends on websockets, caTools, bitops, digest packages.
Q & A:
- Tutorial: http://wch.github.io/shiny/tutorial/
- Layout: http://shiny.rstudio.com/articles/layout-guide.html
Q: If we run runExample('01_hello') in Rserve from an R client, we can continue our work in R client without losing the functionality of the GUI from shiny. Question: how do we kill the job?- If I run the example "01_hello", the browser only shows the control but not graph on Firefox? A: Use Chrome or Opera as the default browser.
- Q: How difficult to put the code in Gist:github? A: Just create an account. Do not even need to create a repository. Just go to http://gist.github.com and create a new gist. The new gist can be secret or public. A secret gist can not be edited again after it is created although it works fine when it was used in runGist() function.
Deploy to run locally
Follow the instruction here, we can do as following (Tested on Windows OS)
- Create a desktop shortcut with target "C:\Program Files\R\R-3.0.2\bin\R.exe" -e "shiny::runExample('01_hello')" . We can name the shortcut as we like, e.g. R+shiny
- Double click the shortcut. The Windows Firewall will be popped up and say it block some features of the program. It does not matter if we choose Allow access or Cancel.
- Look at the command prompt window (black background console window), it will say something like
Listening on port 7510
at the last line of the console. - Open your browser (Chrome or Firefox works), and type the address http://localhost:7510. You will see something magic happen.
- If we don't want to play with it, we can close the browser and close the command console (hit 'x')too.
Deploy on cloud
https://www.r-bloggers.com/deploying-r-rstudio-and-shiny-applications-on-unbuntu-server/
Shiny server series part 1: setting up. It includes setting up A- and CNAME records on DigitalOcean.
Deploy on shinyapps.io
See Getting started with shinyapps.io page.
Limitations of the free account (5 applications, 25 active hours) on shinyapps.io.
Shinyapps.io can accept google account to sign up. I create an account and a test application/instance on
- https://taichimd.shinyapps.io/stock/ (quantmod, ggplot2, reshape2, magrittr, rvest packages were used)
- https://taichimd.shinyapps.io/tspgov (ggplot2, reshape2, magrittr, rvest, plotly)
The R packages our shiny app uses will be automatically downloaded by shinyapps.io service. See the package dependencies section on http://shiny.rstudio.com/articles/shinyapps.html.
After we run rsconnect() command to deploy our apps, a new subfolder rsconnect will be created under our app folder. I add this folder to .gitignore file.
For the shiny apps we uploaded to shinyapps.io, we can download them back. The download bundle will also include packrat subfolder (packrat.lock file and desc subfolder). See here for more about packrat.
Deploy to run remotely -shiny server
If we want to deploy our shiny apps to WWW, we need to install shiny server.
Following the guide on here, shiny-server is up smoothly on my Ubuntu machine. After I run the command sudo gdebi shiny-server-0.4.0.8-amd64.deb, shiny-server is started. Thanks to upstart in Ubuntu, shiny-server is automatically started whenever the machine is started.
Each app directory needs to be copied to /srv/shiny-server/ (which links to /opt/shiny-server/) directory using sudo.
The default port is 3838. That is, the remote computer can access the website using http://xxx.xxx.x.xx:3838/AppName.
Last but not the least, according to its web page, shiny-server is Experimental quality. Use at your own risk!.
Running shiny server as non-root: run_as
- https://stackoverflow.com/questions/36201019/run-shiny-server-as-non-root
- https://support.rstudio.com/hc/en-us/articles/219044787-Root-requirements-for-Shiny-Server
- http://docs.rstudio.com/shiny-server/#run_as
Shiny server installation
RHEL/CentOS 7
https://www.vultr.com/docs/how-to-install-shiny-server-on-centos-7
Raspberry Pi
http://atceiling.blogspot.com/2017/12/raspberry-pi-r-languager-shiny-server.html
R
sudo nano /etc/apt/sources.list # deb http://archive.raspbian.org/raspbian/ stretch main sudo apt-get update sudo apt-get install r-base r-base-core r-base-dev
Shiny-server
sudo apt-get install cmake sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\"" git clone https://github.com/rstudio/shiny-server.git cd shiny-server mkdir tmp cd tmp DIR=`pwd` PATH=$DIR/../bin:$PATH PYTHON=`which python` $PYTHON --version cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DPYTHON="$PYTHON" ../ make mkdir ../build (cd .. && ./bin/npm --python="$PYTHON" install) (cd .. && ./bin/node ./ext/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js --python="$PYTHON" rebuild) sudo make install sudo ln -s /usr/local/shiny-server/bin/shiny-server /usr/bin/shiny-server sudo useradd -r -m shiny sudo mkdir -p /var/log/shiny-server sudo mkdir -p /srv/shiny-server sudo mkdir -p /var/lib/shiny-server sudo chown shiny /var/log/shiny-server sudo mkdir -p /etc/shiny-server cd /etc/shiny-server/ sudo wget http://withr.me/misc/shiny-server.conf sudo shiny-server http://192.168.X.XXX:3838
建立 server.R 及 ui.R 程式
cd /srv/shiny-server mkdir hello_shiny cd hello_shiny # 分別建立 server.R 及 ui.R
Shiny https: Securing Shiny Open Source with SSL
- http://ipub.com/shiny-https/
- ShinyProxy, SHINYPROXY 1.0.2
- https://www.jasperginn.nl/shiny-server-series-pt3/
Deploy your own shiny server
Example of embedding shiny in your web page
http://michaeltoth.me/popularity-of-baby-names-since-1880.html
The R Shiny packages you need for your web apps
http://enhancedatascience.com/2017/07/10/the-packages-you-need-for-your-r-shiny-application/
Shiny + Docker
- See this post. It uses the gui of Docker called Kitematic.
- https://hub.docker.com/r/rocker/shiny/ Don't run R Shiny as a non-root user.
- Shiny Server on Docker: CentOS 7 Edition
- https://github.com/rocker-org/shiny
- https://www.r-bloggers.com/dockerizing-a-shiny-app/
- https://github.com/keberwein/docker_shiny-server_centos7 (Shiny + RStudio servers)
shinydashboard
- http://rstudio.github.io/shinydashboard/
- Dashboards made easy
- Using Shiny with Scheduled and Streaming Data
flexdashboard
- The output can be a static HTML file or a dynamic HTML (shiny document)
- https://rmarkdown.rstudio.com/flexdashboard/
- Introducing flexdashboards. The gauge component is cool.
shinytheme
shiny + databases: pool package
https://blog.rstudio.com/2017/11/17/pool-0-1-3/
tags, hyperlinks
- https://stackoverflow.com/questions/42047422/create-url-hyperlink-in-r-shiny
- Customize your UI with HTML
dates
- https://stackoverflow.com/questions/22834778/r-shiny-daterangeinput-format
- http://www.noamross.net/blog/2014/2/10/using-times-and-dates-in-r---presentation-code.html
websocket
http://illposed.net/jsm2012.pdf
CentOS
- https://www.vultr.com/docs/how-to-install-shiny-server-on-centos-7
- https://github.com/rstudio/shiny-server/wiki/CentOS-step-by-step-Installation-Instructions
- http://blog.supstat.com/2014/05/install-rstudio-server-on-centos6-5/
Gallery
- Shiny User Showcase
- http://www.showmeshiny.com/
- Example of using googleVis: http://shinyeoda.cloudapp.net/
- Integrate with Javascript: https://github.com/wch/shiny-jsdemo and https://github.com/trestletech/ShinyDash-Sample
- interactiveDisplay (Bioconductor package, there is a STOP Application button too): http://www.bioconductor.org/packages/release/bioc/html/interactiveDisplay.html
- Party vote characteristics at the New Zealand General Election 2014, More things with the New Zealand Election Study
- genSurv : An interactive web-based tool for survival analysis in genomics research. The paper and the source code.
- gene2drug
- Stock
- http://shiny.rstudio.com/tutorial/written-tutorial/lesson6/
- Stock Closing Price History.
- Multiple stocks.
- google (flash is required, not accurate eg DOW). msn (Nice).
- yahoo (French only).
- S&P500 Dashboard, Github source code
Persistent data storage in Shiny apps
http://deanattali.com/blog/shiny-persistent-data-storage/
Password protection
- http://ipub.com/shiny-password-protect/
- https://auth0.com/blog/adding-authentication-to-shiny-server/
- https://www.r-bloggers.com/password-protect-shiny-apps/
- Authentication of Shiny-server Application Using a Simple Method
Install all required R packages
http://padamson.github.io/r/shiny/2016/03/13/install-required-r-packages.html
Three R Shiny tricks to make your Shiny app shines (2/3): Semi-collapsible sidebar
Tips
Shiny tips & tricks for improving your apps and solving common problems by Dean Attali.
A Shiny-app Serves as Shiny-server Load Balancer
Shiny-server System Performance Monitoring for Open Source Edition
Real Shiny Examples
- CellMinerDB from NCI/NIH.
- voomDDA: Discovery of Diagnostic Biomarkers and Classification of RNA-Seq Data. https://peerj.com/articles/3890/
- Interactive analysis of metagenomics data
- ExpressionDB, An open source platform for distributing genome-scale datasets
- GREIN : GEO RNA-seq Experiments Interactive Navigator and the paper