Shiny: Difference between revisions
(190 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
[[File:ShinyUpload.png|100px]] | [[File:ShinyUpload.png|100px]] | ||
More shiny examples can be found on https://github.com/rstudio/shiny-examples shiny-examples. | More shiny examples can be found on https://github.com/rstudio/shiny-examples 188 shiny-examples (note this is not what runExample("08_html") used. '''runExample()''' used local files that contain only [https://github.com/rstudio/shiny/tree/main/inst/examples 11 examples]). The local directory is ''/Library/Frameworks/R.framework/Versions/4.2/Resources/library/shiny/'' for R 4.2.x on macOS. | ||
<strike>shiny depends on [http://cran.r-project.org/web/packages/websockets/index.html websockets], caTools, bitops, digest packages.</strike> | <strike>shiny depends on [http://cran.r-project.org/web/packages/websockets/index.html websockets], caTools, bitops, digest packages.</strike> | ||
Line 20: | Line 20: | ||
== Resources == | == Resources == | ||
[https://mastering-shiny.org/ Mastering shiny] Hadley Wickham | * [https://mastering-shiny.org/ Mastering shiny] Hadley Wickham | ||
* [https://plotly-r.com/index.html Interactive web-based data visualization with R, plotly, and shiny] Carson Sievert 2019 | |||
* [https://business-science.github.io/shiny-production-with-aws-book/ Shiny Production with AWS Book] by Matt Dancho | |||
* [https://hosting.analythium.io/the-best-resources-for-learning-shiny/ The Best Resources for Learning Shiny App Development] | |||
* [https://appsilon.com/best-r-shiny-books-and-courses/ Top 7 Best R Shiny Books and Courses That Are Completely Free] | |||
* [https://www.r-bloggers.com/2024/02/level-up-your-r-shiny-team-skills-with-our-free-ebook/ Level Up Your R/Shiny Team Skills with Our Free Ebook] | |||
= Deploy to run locally = | = Deploy to run locally = | ||
[https://hosting.analythium.io/run-shiny-apps-locally/ Run Shiny Apps Locally] 2021 | |||
Follow the instruction [http://rstudio.github.io/shiny/tutorial/#run-and-debug here], we can do as following (Tested on Windows OS) | Follow the instruction [http://rstudio.github.io/shiny/tutorial/#run-and-debug 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''' | # 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''' | ||
Line 29: | Line 36: | ||
# Open your browser (Chrome or Firefox works), and type the address '''http://localhost:7510'''. You will see something magic happen. | # 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. | # If we don't want to play with it, we can close the browser and close the command console (hit 'x')too. | ||
== How to run an R shiny app == | |||
* [https://deanattali.com/blog/building-shiny-apps-tutorial/ Building Shiny apps – an interactive tutorial] by Dean Attali | |||
* Different ways: | |||
** Click "Run App" in RStudio | |||
** Call shiny::runApp(shinyApp(ui=ui, server=server, options = list(port = 3838)) | |||
** Call [https://shiny.rstudio.com/reference/shiny/latest/runApp.html shiny::runApp("~/Directory")] in your R console. This also works if we replaced a directory with an R file. | |||
** R -e "shiny::runApp('~/shinyapp')" from a terminal | |||
* An [https://gist.github.com/senthilthyagarajan/a714446c9acd8127e4cbef6ede09b1fc example] of "app.R". Edit a table via the "DT" package. | |||
* [https://www.mango-solutions.com/turn-shiny-application-into-a-tablet-or-desktop-app/ Turn a shiny application into a tablet or desktop app] | |||
== rmarkdown::run() instead of rmarkdown::render() == | |||
Use rmarkdown::run("XXX.Rmd") file. If you use the render() function, you will receive an error "Error: path for html_dependency not provided Execution". | |||
== RInno == | == RInno == | ||
Line 41: | Line 61: | ||
[https://www.jasperginn.nl/shiny-server-series-pt1/ Shiny server series part 1: setting up]. It includes setting up A- and CNAME records on DigitalOcean. | [https://www.jasperginn.nl/shiny-server-series-pt1/ Shiny server series part 1: setting up]. It includes setting up A- and CNAME records on DigitalOcean. | ||
= Deploy on shinyapps.io = | == Deploy on Github Pages: shinylive == | ||
<ul> | |||
<li>https://posit-dev.github.io/r-shinylive/ | |||
* Shinylive Code Editor https://shinylive.io/r/editor/ | |||
* [https://cloud.r-project.org/web/packages/shinylive/index.html CRAN] (not the latest) | |||
* [https://github.com/posit-dev/r-shinylive/ Github] (latest) | |||
* [https://www.youtube.com/watch?v=RcwvG7dtMqU {shinylive}: Serverless Shiny Apps] | |||
<li>The backend [https://docs.r-wasm.org/webr/latest/ WebR] - R in the Browser (not an R package). | |||
* [https://www.youtube.com/watch?v=KIebBv5kKmU How to run Shiny Apps in your browser with WebR (webr.bundle)] | |||
<li>https://shiny.posit.co/py/docs/shinylive.html Shinylive for Python and [https://github.com/posit-dev/py-shinylive Github] | |||
* [https://www.r-bloggers.com/2024/05/shiny-for-python-shinylive-how-to-run-shiny-for-python-apps-without-a-python-server/ Shiny for Python Shinylive: How to Run Shiny for Python Apps Without a Python Server] | |||
<li>[https://github.com/RamiKrispin/deploy-flex-actions Deploying flexdashboard on Github Pages with Docker and Github Actions] 2022 | |||
<li>[https://github.com/RamiKrispin/shinylive-r Deploy Shinylive R App on Github Pages] and the [https://medium.com/@rami.krispin/deploy-shiny-app-on-github-pages-b4cbd433bdc post on Medium], 2023/9/26. | |||
* It has good links to RStudio/Posit conf about shinylive | |||
* VScode & a dockerized environment | |||
<li>[https://r-posts.com/add-shiny-in-quarto-blog-with-shinylive/ Add shiny in quarto blog with shinylive] 2024/3/10. Suppose we have a file ''app.R'' in ~/Documents/shinylive folder. | |||
* Install shinylive | |||
:<syntaxhighlight lang='r'> | |||
# install.packages("pak") | |||
> pak::pak("posit-dev/r-shinylive") | |||
> packageVersion("shinylive") | |||
[1] ‘0.1.1.9000’ | |||
</syntaxhighlight> | |||
* Method 1: shinylive via web page. Just one line is need. It will output the local URL. [https://arraytools.github.io/shinylive_out/ My testing page on Github]. To put it on github, go to the repository's setting page (make sure the repository is public). Click on "Pages" on LHS. In the Branch, select "main" branch and "/root" directory. | |||
:<syntaxhighlight lang='r'> | |||
> shinylive::export('~/Documents/shinylive', '~/Documents/shinylive_out') | |||
... | |||
Run the following in an R session to serve the app: | |||
httpuv::runStaticServer("~/Documents/shinylive_out") | |||
> httpuv::runStaticServer("~/Documents/shinylive_out") | |||
Serving: '~/Documents/shinylive_out' | |||
View at: http://127.0.0.1:7446 | |||
Press Esc or Ctrl + C to stop the server | |||
</syntaxhighlight> | |||
* Method 2: embed shinylive in Quarto blog. Need to install [https://github.com/quarto-ext/shinylive?tab=readme-ov-file#readme Shinylive Quarto extension] | |||
:<syntaxhighlight lang='r'> | |||
quarto add quarto-ext/shinylive | |||
</syntaxhighlight> | |||
:After that, modify the ''yaml'' of your [https://github.com/zarathucorp/blog/blob/master/posts/2024-03-04-shinylive/index.qmd index.qmd] and put the contents of the app.R in a code chunk. | |||
</ul> | |||
== Deploy to Digital Ocean == | |||
[https://discindo.org/post/how-to-deploy-shiny-application-to-digital-ocean-using-github-actions/ How to deploy Shiny application to Digital Ocean using GitHub Actions] | |||
= Deploy on shinyapps.io: rsconnect package = | |||
About the account | |||
* [http://shiny.rstudio.com/articles/shinyapps.html Getting started with shinyapps.io] page and [https://www.shinyapps.io/admin/#/dashboard Dashboard] page. | |||
* [https://www.shinyapps.io/#pricing Limitations of the free account] (5 applications, 25 active hours per month) on shinyapps.io. | |||
* [https://hosting.analythium.io/how-many-shiny-apps-can-you-host-for-free/ How Many Shiny Apps Can You Host for Free?] | |||
* [https://blog.rmhogervorst.nl/blog/2021/02/27/deploy-to-shinyapps-io-from-github-actions/ Deploy to Shinyapps.io from Github Actions] | |||
* [https://hosting.analythium.io/push-button-publishing-for-shiny-apps/ Push Button Publishing for Shiny Apps] | |||
Shinyapps.io can accept google account to sign up. | |||
* <strike>https://taichimd.shinyapps.io/stock/ (quantmod, ggplot2, reshape2, magrittr, rvest packages were used)</strike> | |||
* <strike>https://taichimd.shinyapps.io/tspgov (ggplot2, reshape2, magrittr, rvest, plotly)</strike>, [https://www.tsp.gov/fund-performance/ Performance] | |||
* https://shiny.taichimd.us/shiny-examples.html 188 shiny examples. [https://gist.github.com/arraytools/e53610426523c91cae0c487b5dd148e0 source code for this HTML] | |||
* https://taichimd.shinyapps.io/Lasso_Simulation/ Lasso with simulated data | |||
* https://taichimd.shinyapps.io/shinysurvival/ Kaplan-Meier curves plotter | |||
* https://taichimd.shinyapps.io/cran-downloads/ (a backup copy of hadley shiny app). Some packages to test: | |||
** ggpubr, survminer, GGally, glmnet, survAUC | |||
** glmnet, SGL, MSGLasso, grplasso, biospear | |||
** dockerfiler, stevedore, babelwhale, liftr | |||
Note: | |||
* https:// | # [https://docs.rstudio.com/shinyapps.io/appendix.html#default-system-packages Default System Packages]. | ||
* https:// | # Two commands are needed to upload an app: | ||
#* [https://rstudio.github.io/rsconnect/reference/setAccountInfo.html rsconnect::setAccountInfo()] [the full command is copied from account's token page. | |||
#* [https://rstudio.github.io/rsconnect/reference/deployApp.html rsconnect::deployApp()] [assume we are in the right working directory]. If the machine contains several accounts, we can use deployApp(account = "XXXX") to specify the account we want to deploy the app. After successful deployment, the browser will open the URL for our app. | |||
# 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. But it seems this file/folder does not contain any secret information. So not worry. | |||
# The ''rsconnect'' stores account information. If we get the app from another account make sure to delete this subfolder before we run ''rsconnect::deployApp()''; otherwise we will get an error message ''Error: HTTP 403 .... Forbidden'''; see [https://community.rstudio.com/t/i-cant-deploy-my-app-with-a-name-that-was-used-in-a-previous-deleted-app/35223 I can't deploy my app with a name that was used in a previous deleted app]. | |||
# 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 [[R_packages#packrat_.28reproducible_search.29:_project_specific_package_managment|R packages → packrat]] for more about packrat. | |||
Caveats: | |||
# I cannot upload my shiny app [https://taichimd.shinyapps.io/shinysurvival/ shinySurvival] when it contains data in a subdirectory. | |||
# When the app is running perfectly locally, it gives some errors when it is deployed to the shinyapps.io. Looking at the app log does not help too much. | |||
== deployApp() == | |||
<ul> | |||
<li>Choose which files ignored deploy to shinyapps.io. See [https://www.r-bloggers.com/2021/02/deploy-to-shinyapps-io-from-github-actions/ Deploy to Shinyapps.io from Github Actions] | |||
<pre> | |||
deployApp(, appFiles= c("app.R" #, you can specify which files to deploy, | |||
#or keep this NULL to deploy everything | |||
), | |||
appName = error_on_missing_name("MASTERNAME"), | |||
appTitle = "shinyapplication") | |||
</pre> | |||
</ul> | |||
= | == Packages == | ||
[https:// | <ul> | ||
<li>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 and [https://docs.rstudio.com/shinyapps.io/getting-started.html#using-your-r-packages-in-the-cloud Using your R packages in the cloud]. | |||
<li>When you deploy your application, the '''rsconnect''' package detects the packages that your application uses by looking for explicit '''library()''' calls within your application. Be aware that you should not have an explicit '''install.packages()''' call within your ui.R or server.R files. | |||
<li>Currently the shinyapps.io service supports deploying packages installed from '''CRAN, GitHub''', and '''BioConductor'''. | |||
<li>[https://rdrr.io/cran/rsconnect/man/appDependencies.html rsconnect::appDependencies()] - Recursively detect all package dependencies for an application. | |||
<li>Error when trying to deploy to shinyapps.io: Application depends on package "package" but it is not. You have to fool the shinyapps (or rsconnect) package a bit so that it does not detect package as a literal package name. | |||
<pre> | |||
do.call(library, list(package = package, character.only = TRUE)) | |||
</pre> | |||
<li>How to specify package versions when deploying Shiny app to shinyapps.io? See the next item. | |||
<li>[https://community.rstudio.com/t/shiny-app-which-depends-on-package-on-github/46354 Shiny app which depends on package on GitHub?] '''You should not install packages inside your shiny app, just install it locally and rsconnect will figure out how to install it based on your local library, you just have to load the library inside your app.''' Remember [https://rdrr.io/r/utils/packageDescription.html packageDescription()] records all information even a package installed from a specific commit from Github repository. | |||
<li>(Is this outdated?) In order for BioConductor packages to install succesfully on shinyapps.io, the '''repos''' option must be configured, either directly or by using '''setRepositories()''', to include the BioConductor repositories in addition to CRAN. [https://rdrr.io/r/utils/setRepositories.html setRepositories()] | |||
<pre> | |||
setRepositories(addURLs = c(BioC = "https://bioconductor.org/packages/3.8/bioc")) | |||
</pre> | |||
<li>[https://stackoverflow.com/a/73145538 Deploy shiny app using custom package]. Also use '''renv''' or '''packrat''' package. | |||
<li>[https://community.rstudio.com/t/how-to-manage-r-package-dependencies-for-shiny-app-deployment-docker/18593/2 How to manage R package dependencies for shiny app deployment (docker)] packrat | |||
<li>[https://support.posit.co/hc/en-us/articles/216528108-Deploying-packrat-projects-to-Shiny-Server-Pro Deploying packrat projects to Shiny Server Pro] packrat | |||
<li>[https://debruine.github.io/shinyintro/sharing.html Building Web Apps with R Shiny] ebook | |||
<li>[https://www.r-bloggers.com/2021/02/deploy-to-shinyapps-io-from-github-actions/ Deploy to Shinyapps.io from Github Actions] | |||
</ul> | |||
== Deploying a development version of a shiny app == | |||
<pre> | |||
rsconnect::deployApp(..., appName="MyApp") | |||
rsconnect::deployApp(..., appName="MyApp_dev") | |||
</pre> | |||
= Shiny server installation = | = Shiny server installation = | ||
Line 64: | Line 189: | ||
The default port is 3838. That is, the remote computer can access the website using http://xxx.xxx.x.xx:3838/AppName. | The default port is 3838. That is, the remote computer can access the website using http://xxx.xxx.x.xx:3838/AppName. | ||
== Release == | |||
[https://blog.rstudio.com/2021/01/13/shiny-server-1-5-16-update/ Shiny Server 1.5.16 Update] 2021-01-03 | |||
== Ubuntu & firewall == | == Ubuntu & firewall == | ||
In my case, I need to modify the firewall to allow traffic through to Shiny Server '''sudo ufw allow 3838'''. See [https://www.digitalocean.com/community/tutorials/how-to-set-up-shiny-server-on-ubuntu-16-04 How to Set Up Shiny Server on Ubuntu 16.04]. The tutorial also covers '''Securing Shiny Server with a Reverse Proxy and SSL Certificate'''. | * In my case, I need to modify the firewall to allow traffic through to Shiny Server '''sudo ufw allow 3838'''. See [https://www.digitalocean.com/community/tutorials/how-to-set-up-shiny-server-on-ubuntu-16-04 How to Set Up Shiny Server on Ubuntu 16.04]. The tutorial also covers '''Securing Shiny Server with a Reverse Proxy and SSL Certificate'''. | ||
* [https://blog.rwhitedwarf.com/post/deploy_shiny_on_debian/ Deploy your own Shiny app server with debian] 2023-1 | |||
== RHEL/CentOS 7 == | == RHEL/CentOS 7 == | ||
Line 72: | Line 201: | ||
== Raspberry Pi == | == Raspberry Pi == | ||
http://atceiling.blogspot.com/2017/12/raspberry-pi-r-languager-shiny-server.html | * [https://andresrcs.rbind.io/2021/01/13/raspberry_pi_server/ Automatically installing Shiny and RStudio server on Raspberry Pi OS with Ansible] 2021-01-13 | ||
* http://atceiling.blogspot.com/2017/12/raspberry-pi-r-languager-shiny-server.html | |||
R | R | ||
Line 138: | Line 268: | ||
* https://support.rstudio.com/hc/en-us/articles/219044787-Root-requirements-for-Shiny-Server | * https://support.rstudio.com/hc/en-us/articles/219044787-Root-requirements-for-Shiny-Server | ||
* http://docs.rstudio.com/shiny-server/#run_as | * http://docs.rstudio.com/shiny-server/#run_as | ||
== Google analytics == | |||
https://docs.rstudio.com/shiny-server/#google-analytics | |||
== Reverse proxy: Deploy your own shiny server == | == Reverse proxy: Deploy your own shiny server == | ||
Line 144: | Line 277: | ||
* [http://freerangestats.info/blog/2018/07/07/twitter-monitor Setting up RStudio Server, Shiny Server and PostgreSQL] | * [http://freerangestats.info/blog/2018/07/07/twitter-monitor Setting up RStudio Server, Shiny Server and PostgreSQL] | ||
* When used with cloudflare, we should disable HTTP proxy (CDN) and use DNS only. | * When used with cloudflare, we should disable HTTP proxy (CDN) and use DNS only. | ||
* [https://andresrcs.rbind.io/2021/08/16/port_forwarding/ How to make your home Shiny or Rstudio Server accessible from the public internet] | |||
== Shiny https: Securing Shiny Open Source with SSL == | == Shiny https: Securing Shiny Open Source with SSL == | ||
* http://ipub.com/shiny-https/ | * http://ipub.com/shiny-https/ | ||
* [https://www.openanalytics.eu/blog/shinyproxy-060-released ShinyProxy] | * [https://www.openanalytics.eu/blog/shinyproxy-060-released ShinyProxy] | ||
** [https://www.openanalytics.eu/blog/2017/11/12/shinyproxy-1.0.2/ SHINYPROXY 1.0.2] | |||
** [https://www.databentobox.com/2020/05/03/secure-shinyproxy/ Securing and monitoring ShinyProxy deployment of R Shiny apps] | |||
* https://www.jasperginn.nl/shiny-server-series-pt3/ | * https://www.jasperginn.nl/shiny-server-series-pt3/ | ||
= | == Securing Shiny Server with Caddy == | ||
* [https:// | * [https://hosting.analythium.io/securing-shiny-server-with-caddy/ Securing Shiny Server with Caddy] | ||
* [https://hosting.analythium.io/file-transfer-based-publishing-for-shiny-apps/ File Transfer Based Publishing for Shiny Apps] | |||
* | |||
* | = Shiny for Python = | ||
https://shiny.rstudio.com/py/ | |||
= Shiny Assistant = | |||
* https://gallery.shinyapps.io/assistant/# | |||
* [https://shiny.posit.co/blog/posts/shiny-assistant/?s=09 Shiny assistant] 2024/10/9 | |||
= Simplifying Parts Of A Shiny App by Creating Functions = | |||
[https://thatdatatho.com/simplifying-r-shiny-app-functions/ Simplifying Parts Of A Shiny App by Creating Functions] | |||
= shinyuieditor = | |||
[https://rstudio.github.io/shinyuieditor/articles/quick-start.html shinyuieditor] package | |||
= Shiny UI Prototype Builder = | |||
[https://ashbaldry.github.io/designer/ designer] package | |||
= How to Build a Data Analysis App in R Shiny = | |||
[https://towardsdatascience.com/how-to-build-a-data-analysis-app-in-r-shiny-143bee9338f7 How to Build a Data Analysis App in R Shiny] | |||
= | = Landing page = | ||
* We can create an HTML file in /srv/shiny-server directory as the landing page where each app is under a sub-directory. | |||
* [https://apps.machlis.com/ R Shiny Apps by Sharon Machlis] | |||
* [https://cran.r-project.org/web/packages/shinyLP/index.html shinyLP] package. Bootstrap Landing Home Pages for Shiny Applications | |||
* [https://docs.rstudio.com/shiny-server/#host-a-directory-of-applications-1 Host a directory of applications] from Shiny Server Professional v1.5.17 Administrator's Guide | |||
= The R Shiny packages you need for your web apps = | = The R Shiny packages you need for your web apps = | ||
https://www.r-bloggers.com/2017/07/the-r-shiny-packages-you-need-for-your-web-apps/ | |||
== Other web apps == | |||
[https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1009663 Ten simple rules for researchers who want to develop web apps] | |||
= Shiny + Docker = | = Shiny + Docker = | ||
Line 171: | Line 328: | ||
* https://www.r-bloggers.com/dockerizing-a-shiny-app/ | * https://www.r-bloggers.com/dockerizing-a-shiny-app/ | ||
* https://github.com/keberwein/docker_shiny-server_centos7 (Shiny + RStudio servers) | * https://github.com/keberwein/docker_shiny-server_centos7 (Shiny + RStudio servers) | ||
* [https://www.statworx.com/de/blog/how-to-dockerize-shinyapps/ How To Dockerize ShinyApps] + renv package | |||
* [https://telethonkids.wordpress.com/2019/02/08/deploying-an-r-shiny-app-with-docker/ Deploying an R Shiny App With Docker] | * [https://telethonkids.wordpress.com/2019/02/08/deploying-an-r-shiny-app-with-docker/ Deploying an R Shiny App With Docker] | ||
* [https://blog.sellorm.com/2021/04/25/shiny-app-in-docker/?s=09 Running a shiny app in a docker container] | |||
* [https://hosting.analythium.io/dockerized-shiny-apps-with-dependencies/ Dockerized Shiny Apps with Dependencies]. renv | |||
* [https://hosting.analythium.io/host-shiny-apps-with-docker/ Host Shiny Apps with Docker] | |||
* [https://hosting.analythium.io/using-systemd-to-run-shiny-apps/ Using systemd to Run Shiny Apps] | |||
* [https://hosting.analythium.io/running-shiny-server-in-docker/ Running Shiny Server in Docker] | |||
* [https://hosting.analythium.io/shiny-apps-with-docker-compose-part-1-development/ Shiny Apps with Docker Compose, Part 1: Development] 2021 | |||
* [https://github.com/openbiox/UCSCXenaShiny UCSCXenaShiny]: An R package for interactively exploring UCSC Xena | |||
* [https://www.jumpingrivers.com/blog/shiny-auto-docker/ Automating Dockerfile creation for Shiny apps] 2022/10/20 | |||
* [https://www.r-bloggers.com/2023/11/r-shiny-docker-how-to-run-shiny-apps-in-a-docker-container/ R Shiny Docker: How To Run Shiny Apps in a Docker Container] 2023/11/28 | |||
= Dashboard = | |||
* [https://www.tychobra.com/posts/2020-07-17-a-dashboard-of-polished-shiny-apps/ A Dashboard of Shiny Apps] | |||
* [https://blog.rstudio.com/2020/07/21/4-tips-to-make-your-shiny-dashboard-faster/ 4 Tips to Make Your Shiny Dashboard Faster] | |||
* [https://appsilon.com/dashboards-in-rshiny/ Dashboards in R Shiny] | |||
= [https://cran.r-project.org/web/packages/shinydashboard/index.html shinydashboard] = | == [https://cran.r-project.org/web/packages/shinydashboard/index.html shinydashboard] == | ||
* http://rstudio.github.io/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] = | == [https://cran.rstudio.com/web/packages/flexdashboard/ flexdashboard] == | ||
* The output can be a static HTML file or a dynamic HTML (using shiny, highcharter, viridisLite, ...) | * The output can be a static HTML file or a dynamic HTML (using shiny, highcharter, viridisLite, ...) | ||
* https://rmarkdown.rstudio.com/flexdashboard/ | * https://rmarkdown.rstudio.com/flexdashboard/ | ||
Line 186: | Line 358: | ||
* [https://datascienceplus.com/automated-dashboard-with-various-correlation-visualizations-in-r/ Automated Dashboard with various correlation visualizations in R] | * [https://datascienceplus.com/automated-dashboard-with-various-correlation-visualizations-in-r/ Automated Dashboard with various correlation visualizations in R] | ||
* [https://www.timlrx.com/2019/12/17/speeding-up-r-plotly-webapps-r-x-javascript-part-i/ Speeding up R Plotly web apps - R x Javascript part I] | * [https://www.timlrx.com/2019/12/17/speeding-up-r-plotly-webapps-r-x-javascript-part-i/ Speeding up R Plotly web apps - R x Javascript part I] | ||
= shinyalert: create pretty popup messages (modals) in Shiny = | |||
[https://github.com/daattali/shinyalert shinyalert] | |||
= shinyjs = | |||
[https://github.com/daattali/shinyjs shinyjs] | |||
= Dash bio for R = | = Dash bio for R = | ||
[https://moderndata.plot.ly/introducing-dash-bio-for-r/ Introducing Dash Bio for R] | [https://moderndata.plot.ly/introducing-dash-bio-for-r/ Introducing Dash Bio for R] | ||
= | = Theme = | ||
= shiny + databases: | == shinytheme == | ||
https://blog.rstudio.com/2017/11/17/pool-0-1-3/ | * [https://blog.rstudio.org/2016/10/13/shinythemes-1-1-1/ shinythemes 1.1.1] | ||
* [https://medium.com/@PedroLinsMMC/build-your-own-interactive-data-driven-web-app-a-step-by-step-guide-2485c7b2a9bd Build Your Own Interactive Data-Driven Web App: A Step-by-Step Guide] | |||
== bslib == | |||
[https://appsilon.com/r-shiny-bslib/ R Shiny bslib – How to Work With Bootstrap Themes in Shiny] | |||
== bootstraplib == | |||
[https://www.programmingwithr.com/how-to-use-bootstraplib-s-live-theme-previewer-to-customize-shiny-apps/ How to use bootstraplib's Live Theme Previewer to customize Shiny apps?] | |||
= shiny + databases = | |||
* [https://roh.engineering/post/shiny-in-production-app-and-database-syncing/ Shiny in Production: App and Database Syncing] | |||
* [https://blog.rstudio.com/2017/11/17/pool-0-1-3/ shiny + databases: pool package] | |||
= tags, hyperlinks = | = tags, hyperlinks = | ||
Line 205: | Line 393: | ||
= websocket = | = websocket = | ||
http://illposed.net/jsm2012.pdf | * http://illposed.net/jsm2012.pdf | ||
* https://blog.teamtreehouse.com/an-introduction-to-websockets | |||
= CentOS = | = CentOS = | ||
Line 213: | Line 402: | ||
= Gallery = | = Gallery = | ||
* https://github.com/rstudio/shiny-examples | |||
<pre> | |||
git clone https://github.com/rstudio/shiny-examples.git | |||
shiny::runApp("~/github/shiny-examples/018-datatable-options/") | |||
</pre> | |||
* [https://www.rstudio.com/products/shiny/shiny-user-showcase/ Shiny User Showcase] | * [https://www.rstudio.com/products/shiny/shiny-user-showcase/ Shiny User Showcase] | ||
* [https://blog.rstudio.com/2021/02/12/shiny-app-stories/ Introducing Shiny App Stories] | |||
* http://www.showmeshiny.com/ | * http://www.showmeshiny.com/ | ||
* Example of using googleVis: http://shinyeoda.cloudapp.net/ | * Example of using googleVis: http://shinyeoda.cloudapp.net/ | ||
Line 219: | Line 414: | ||
* interactiveDisplay (Bioconductor package, there is a STOP Application button too): http://www.bioconductor.org/packages/release/bioc/html/interactiveDisplay.html | * interactiveDisplay (Bioconductor package, there is a STOP Application button too): http://www.bioconductor.org/packages/release/bioc/html/interactiveDisplay.html | ||
* [https://ellisp.shinyapps.io/nzes2014_x_by_party/ Party vote characteristics at the New Zealand General Election 2014], [http://ellisp.github.io/blog/2017/08/20/nzes-so-far More things with the New Zealand Election Study] | * [https://ellisp.shinyapps.io/nzes2014_x_by_party/ Party vote characteristics at the New Zealand General Election 2014], [http://ellisp.github.io/blog/2017/08/20/nzes-so-far More things with the New Zealand Election Study] | ||
* [http://www.biosoft.hacettepe.edu.tr/geneSurv/ | * [http://www.biosoft.hacettepe.edu.tr/geneSurv/ geneSurv] : An interactive web-based tool for survival analysis in genomics research. The [http://www.sciencedirect.com/science/article/pii/S001048251730286X paper] and the [https://github.com/selcukorkmaz/geneSurv source] code. | ||
* [https://www.biorxiv.org/content/early/2017/09/21/192005.1 gene2drug] | * [https://www.biorxiv.org/content/early/2017/09/21/192005.1 gene2drug] | ||
* Stock | * Stock | ||
Line 231: | Line 426: | ||
= Persistent data storage in Shiny apps = | = Persistent data storage in Shiny apps = | ||
http://deanattali.com/blog/shiny-persistent-data-storage/ | http://deanattali.com/blog/shiny-persistent-data-storage/ | ||
= multiple outputs to mainPanel = | |||
https://stackoverflow.com/a/27383312. Or use fluidRow() to expand the output in one tabPanel. | |||
<pre> | |||
ui <- navbarPage("My App", | |||
tabPanel("Lasso", | |||
sidebarLayout( | |||
sidebarPanel( | |||
... | |||
), | |||
mainPanel( | |||
tabsetPanel( | |||
tabPanel("CV plot", plotOutput("plotLasso")), | |||
tabPanel("Lasso fitting", | |||
#verbatimTextOutput("fitLasso")) | |||
fluidRow( | |||
column(12, TextOutput("fitLasso", inline=T)), | |||
column(12, verbatimTextOutput("fitLasso2")) | |||
)) | |||
) | |||
) # close mainPanel | |||
) # close sidebarLayout | |||
), # close tabPanel Lasso | |||
) #close navbar page | |||
server <- function(input, output, session) { | |||
output$fitLasso <- renderText({ }) | |||
output$fitLasso2 <- renderPrint({ }) | |||
} | |||
shinyApp(ui, server) | |||
</pre> | |||
= navbarPage = | |||
[https://stackoverflow.com/questions/57890541/how-to-get-the-selected-tab-id-in-a-navbarpage-with-modules How to get the selected Tab-ID in a navbarPage with modules] | |||
= HTML = | |||
<ul> | |||
<li>[https://shiny.rstudio.com/articles/html-tags.html Customize your UI with HTML] | |||
<pre> | |||
# adding the new div tag to the sidebar | |||
tags$div(class="header", checked=NA, | |||
tags$p("Ready to take the Shiny tutorial? If so"), | |||
tags$a(href="shiny.rstudio.com/tutorial", "Click Here!") | |||
</pre> | |||
<li>[https://shiny.rstudio.com/articles/html-ui.html Build your entire UI with HTML]. ''This seems to be a more complicated approach'' at first glance. | |||
<pre> | |||
<application-dir> | |||
|-- app.R | |||
|-- www | |||
|-- index.html | |||
</pre> | |||
and "app.R" | |||
<pre> | |||
# ui is defined in the HTML file | |||
server <- function(input, output) { } | |||
shinyApp(ui = htmlTemplate("www/index.html"), server) | |||
</pre> | |||
<li>[https://shiny.rstudio.com/articles/templates.html HTML templates] | |||
<li>[https://shiny.rstudio.com/articles/tag-glossary.html Shiny HTML Tags Glossary] | |||
</ul> | |||
= Conditional input = | |||
* [https://shiny.rstudio.com/reference/shiny/latest/conditionalPanel.html conditionalPanel()], [https://shiny.rstudio.com/reference/shiny/latest/selectInput.html selectInput()] | |||
* [https://stackoverflow.com/questions/41468333/checkboxinput-and-conditionalpanel-in-shiny checkboxInput and conditionalPanel in shiny] | |||
= Upload a file/files = | |||
* https://shiny.rstudio.com/articles/upload.html. fileInput(), renderTable(), tableOutput(). Add ''options(shiny.maxRequestSize = 30*1024^2)'' to increase the upload size to eg 30MB. | |||
* [https://youtu.be/Qfdd73ICDiA how to upload and access multiple CSV files in R Shiny], [https://github.com/aagarw30/R-Shinyapp-Tutorial/tree/master/Fileinput_uploadmultiplefiles source code]. renderTable(), renderPrint(), renderUI(). | |||
* [https://youtu.be/qdnALNvYIYo demo upload a zip file and unzip it to local machine]. [https://github.com/aagarw30/R-Shinyapp-Tutorial/tree/master/fileinput_uploadzip_file Source code]. observeEvent() | |||
* [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5580407/ CASAS: Cancer Survival Analysis Suite, a web based application] | |||
* [https://github.com/rstudio/shiny/issues/3596 fileInput "accept" not filtering options]. The RStudio built in web browser does not use the accept attribute. It will always show "All Files (*)" if you view your shiny app through RStudio. The '''RStudio built in web browser''' does not use the accept attribute. It will always show "All Files (*)" if you view your shiny app through RStudio. | |||
= reactive = | |||
* [https://shiny.rstudio.com/tutorial/written-tutorial/lesson4/ Lesson 4 Display reactive output] | |||
* [https://shiny.rstudio.com/articles/reactivity-overview.html Reactivity - An overview] | |||
* [https://shiny.rstudio.com/reference/shiny/latest/reactive.html ?reactive], [https://shiny.rstudio.com/tutorial/written-tutorial/lesson6/ Lesson 6 Use reactive expressions] | |||
* [https://mastering-shiny.org/basic-reactivity.html 3 Basic reactivity] from '''Mastering Shiny''' | |||
* [https://turtletopia.github.io/2022/08/31/shiny-reactivity-tricks-pt-ii-reactives-factories/ Shiny Reactivity Tricks, pt. II: Reactives Factories] | |||
= actionButton and isolate = | |||
* https://shiny.rstudio.com/articles/isolation.html | |||
* [https://gallery.shinyapps.io/049-isolate-demo/ 049-isolate-demo] | |||
* It seems isolate() will always run the code one time. So consider '''eventReactive()''' or '''observeEvent()''' instead. | |||
== actionButton and eventReactive* == | |||
[https://youtu.be/40hr8oF_a0E?t=181 R Shiny App Tutorial | eventReactive() demo | Create dependency on actionButton] | |||
== actionButton, observeEvent and reactiveValues == | |||
<ul> | |||
<li>[https://shiny.rstudio.com/reference/shiny/0.11/reactiveValues.html ?reactiveValues] | |||
<li>Based on the following 2 examples. It seems | |||
* reactiveValues() and observeEvent() work together. | |||
* reactiveValues() will create a global variable and its value will be changed based on an actionButton. | |||
* the effect of '''observeEvent() + reactiveValues()''' is similar to '''eventReactive()''' if we don't consider the situation that the new value depends on the old value. | |||
<li>[https://riptutorial.com/shiny/example/32342/reactivevalues reactiveValues example] | |||
<pre> | |||
text_reactive <- reactiveValues( | |||
text = "No text has been submitted yet." | |||
) | |||
observeEvent(input$submit, { | |||
text_reactive$text <- input$user_text | |||
}) | |||
output$text <- renderText({ | |||
text_reactive$text | |||
}) | |||
</pre> | |||
eventReactive() way: | |||
<pre> | |||
text <- eventReactive(input$submit, { | |||
input$user_text | |||
}) | |||
output$text <- renderText({ | |||
text() | |||
}) | |||
</pre> | |||
<li>[https://youtu.be/ML54auObmL8 reactiveValues() in R Shiny - Example 1 - A counter] (video) | |||
<pre> | |||
counter <- reactiveValues(countervalue = 0) | |||
observeEvent(input$add1, | |||
counter$countervalue <- counter$countervalue + 1 | |||
output$counter <- renderText({ | |||
counter$countervalue | |||
}) | |||
</pre> | |||
The following code will break (Error in : C stack usage 7969216 is too close to the limit). So this is the case eventReactive() can't replace reactiveValues()! | |||
<pre> | |||
countervalue <- eventReactive(input$add1, { | |||
countervalue() + 1 | |||
}) | |||
output$counter <- renderText({ | |||
countervalue() | |||
}) | |||
</pre> | |||
</ul> | |||
= Dynamic UI = | |||
* [https://shiny.rstudio.com/articles/dynamic-ui.html Build a dynamic UI that reacts to user input]. reactive(), observeEvent() | |||
** http://wch.github.io/shiny/tutorial/#dynamic-ui | |||
* [https://shiny.rstudio.com/gallery/dynamic-ui.html Dynamically generated user interface components] | |||
* [https://towardsdatascience.com/dynamic-ui-in-shiny-incl-demo-app-a6fb791be4c6 Dynamic UI in Shiny (incl. demo app)] complicated! | |||
* Youtube | |||
** [https://youtu.be/JUop-YfRAuw R Shiny app tutorial # 13 a - how to use renderUI() and uiOutput() in shiny - Dynamic input widgets] | |||
** [https://youtu.be/mHRVFMQ54ZE (R Shiny Basic App) #8 Dynamically create Drop Down List] source code in [https://github.com/KunaalNaik/YT_R_Shiny_Dashboards/tree/master/1%20Basic%20App github]. Code is short. reactive(), observe(), [https://shiny.rstudio.com/reference/shiny/latest/selectInput.html selectInput()], updateSelectInput(). | |||
== eventReactive() == | |||
<ul> | |||
<li>[https://gallery.shinyapps.io/028-actionbutton-demo/ 028-actionbutton-demo] actionButton() and eventReactive() | |||
<li>[https://shiny.rstudio.com/articles/action-buttons.html Using Action and Reset Buttons] actionButton(), reactiveValues(), observeEvent() and eventReactive() | |||
<li>https://shiny.rstudio.com/reference/shiny/1.0.3/observeEvent.html | |||
<li>[https://mastering-shiny.org/reactivity-objects.html observeEvent() and eventReactive()] from Mastering Shiny | |||
<li>[https://stackoverflow.com/a/33520706 Shiny: what is the difference between observeEvent and eventReactive?] | |||
* '''eventReactive'''(eventExpr, handlerExpr, ...) creates a reactive value that changes based on the eventExpr. It seems we do not care much about the returned value. ''handleExpr'' is like output$SOMETHING. | |||
* '''observeEvent'''(eventExpr, valueExpr, ...) simply is triggered based on eventExpr. It returns a reactive expression object. | |||
</li> | |||
</ul> | |||
= Files = | = Files = | ||
Line 241: | Line 599: | ||
* https://www.r-bloggers.com/password-protect-shiny-apps/ | * https://www.r-bloggers.com/password-protect-shiny-apps/ | ||
* [http://withr.me/authentication-of-shiny-server-application-using-a-simple-method/ Authentication of Shiny-server Application Using a Simple Method] | * [http://withr.me/authentication-of-shiny-server-application-using-a-simple-method/ Authentication of Shiny-server Application Using a Simple Method] | ||
* [https://www.tychobra.com/posts/2019-01-03-firebasse-auth-wtih-shiny/ Adding Firebase Authentication to Shiny], [https://www.tychobra.com/posts/2019_08_27_announcing_polished/ Polished - Modern Authentication for Shiny] 2019 | * [https://cran.r-project.org/web/packages/polished/index.html Polished] is an R package that adds authentication and user administration to your Shiny apps. | ||
** [https://www.tychobra.com/posts/2019-01-03-firebasse-auth-wtih-shiny/ Adding Firebase Authentication to Shiny], [https://www.tychobra.com/posts/2019_08_27_announcing_polished/ Polished - Modern Authentication for Shiny] 2019 | |||
** [https://www.tychobra.com/posts/2020-08-26-polished-email-templates/ New Polished Feature - Email Templates] 2020 | |||
= Install all required R packages = | = Install all required R packages = | ||
http://padamson.github.io/r/shiny/2016/03/13/install-required-r-packages.html | http://padamson.github.io/r/shiny/2016/03/13/install-required-r-packages.html | ||
= Icons = | |||
<ul> | |||
<li>[https://appsilon.com/r-shiny-fontawesome-icons/ R Shiny & FontAwesome Icons – How to Use Them in Your Dashboards] | |||
<li>[https://community.rstudio.com/t/image-not-showing-r-shiny-displayed-as-broken/102750 Image not showing R Shiny (displayed as broken)] | |||
* Put the png file in the '''www''' directory | |||
* Put your R code in the app.R file and run it through runApp() or the '''Run App''' icon in RStudio. It does not work if we call it by shinyApp() function. | |||
<li>Example | |||
<syntaxhighlight lang='r'> | |||
library(shiny) | |||
library(survival) | |||
ui <- fluidPage( | |||
titlePanel( | |||
title = tags$div(tags$img(src = "icon.png", height = "32px", width = "32px"), | |||
"Interactive Kaplan Meier Plot", | |||
style = "background-color: black; color: white; padding: 10px;")), | |||
sidebarLayout( | |||
sidebarPanel( | |||
radioButtons("survivalType", "Choose survival data type:", | |||
choices = list("Overall Survival" = "os", "Progression Free Survival" = "pfs"), | |||
selected = "os") | |||
), | |||
mainPanel( | |||
plotOutput("kmPlot") | |||
) | |||
) | |||
) | |||
</syntaxhighlight> | |||
</ul> | |||
= How do I add a favicon to my Shiny app = | |||
Adding a favicon to your Shiny app can be done by placing the favicon file in the www directory of your Shiny app and then using the tags$link function in your UI to link to it. Here’s how you can do it: | |||
<ol> | |||
<li>Place your favicon file (e.g., favicon.ico) in the www directory of your Shiny app. | |||
<li>In your UI, add the following line inside the fluidPage or navbarPage function: | |||
<pre> | |||
tags$head(tags$link(rel = "shortcut icon", href = "favicon.ico", type = "image/x-icon")) | |||
</pre> | |||
<li>Here’s an example of how it might look in a Shiny app: | |||
<pre> | |||
ui <- fluidPage( | |||
titlePanel("My Shiny App"), | |||
tags$head(tags$link(rel = "shortcut icon", href = "favicon.ico", type = "image/x-icon")), | |||
# Rest of your UI code... | |||
) | |||
server <- function(input, output) { | |||
# Your server code... | |||
} | |||
shinyApp(ui = ui, server = server) | |||
</pre> | |||
</ol> | |||
Websites to convert an image to a favicon: | |||
* https://www.favicon-generator.org/ | |||
* https://favicon.io/ | |||
* https://www.favicongenerator.com/ | |||
= Building a Shiny App as a Package = | = Building a Shiny App as a Package = | ||
https://rtask.thinkr.fr/blog/building-a-shiny-app-as-a-package/ | * https://rtask.thinkr.fr/blog/building-a-shiny-app-as-a-package/ | ||
* [https://bryer.org/post/2021-02-12-shiny_apps_in_r_packages/ Framework for Shiny Apps in R Packages] | |||
= Collapsible menu = | = Collapsible menu = | ||
Line 259: | Line 680: | ||
= Tables = | = Tables = | ||
* [https://blog.rstudio.com/2020/09/15/announcing-the-2020-rstudio-table-contest/ Announcing the 2020 RStudio Table Contest] | |||
* [https://www.r-bloggers.com/edit-datatables-in-r-shiny-app/ Edit datatables in R shiny app]. It uses [https://rstudio.github.io/DT/ DT] package. | * [https://www.r-bloggers.com/edit-datatables-in-r-shiny-app/ Edit datatables in R shiny app]. It uses [https://rstudio.github.io/DT/ DT] package. | ||
* [https://glin.github.io/reactable/index.html reactable] | * [https://glin.github.io/reactable/index.html reactable] | ||
** [https://www.infoworld.com/article/3543297/how-to-create-tables-in-r-with-expandable-rows.html How to create tables in R with expandable rows] | |||
= Multimedia = | |||
[https://ashbaldry.github.io/2022-07-20-shiny-multimedia/ Shiny and Reactive Multimedia] | |||
= Math formula = | |||
* [https://shiny.rstudio.com/gallery/mathjax.html mathjax] | |||
* [https://www.r-bloggers.com/2015/12/write-in-line-equations-in-your-shiny-application-with-mathjax/ Write in-line equations in your Shiny application with MathJax] | |||
= shinyMatrix = | |||
* https://cran.r-project.org/web/packages/shinyMatrix/index.html shinyMatrix: Shiny Matrix Input Field] | |||
* [https://blog.rstudio.com/2021/09/29/how-to-use-shinymatrix-and-plotly-graphs/ How to Use shinyMatrix and plotly Graphs as Inputs in a Shiny App] | |||
= Tree = | |||
[https://github.com/shinyTree/shinyTree shinyTree] | |||
= D3 = | = D3 = | ||
Line 274: | Line 711: | ||
= Debug = | = Debug = | ||
[https://blog.rstudio.com/2019/04/26/shiny-1-3-2/ reactlog]: Visually debug your reactivity issues | * [https://blog.rstudio.com/2019/04/26/shiny-1-3-2/ reactlog]: Visually debug your reactivity issues | ||
* [https://shiny.rstudio.com/articles/debugging.html Debugging Shiny applications] | |||
= Talks = | = Talks = | ||
Line 281: | Line 719: | ||
= Tips = | = Tips = | ||
[http://deanattali.com/blog/advanced-shiny-tips/ Shiny tips & tricks for improving your apps and solving common problems] by Dean Attali. | [http://deanattali.com/blog/advanced-shiny-tips/ Shiny tips & tricks for improving your apps and solving common problems] by Dean Attali. | ||
== Adding a website == | |||
[https://www.r-bloggers.com/2023/09/adding-a-website-next-to-your-shiny-server/ Adding a website next to your Shiny server] | |||
== A Guide to Benchmarking Memory Usage == | |||
[https://www.r-bloggers.com/2023/11/maximizing-efficiency-a-guide-to-benchmarking-memory-usage-in-shiny-apps/ Maximizing Efficiency: A Guide to Benchmarking Memory Usage in Shiny Apps] | |||
= Recreating a Shiny App with Flask = | |||
[https://www.jumpingrivers.com/blog/r-shiny-python-flask/ Recreating a Shiny App with Flask] | |||
== Webhook == | |||
Flask, a popular web framework. | |||
This example assumes that you have a server running at https://yourserver.com/webhook that is set up to receive POST requests. | |||
<syntaxhighlight lang='python'> | |||
from flask import Flask, request | |||
app = Flask(__name__) | |||
@app.route('/webhook', methods=['POST']) | |||
def respond(): | |||
print(request.json) | |||
return {'status': 'success'}, 200 | |||
if __name__ == '__main__': | |||
app.run(port=5000, debug=True) | |||
</syntaxhighlight> | |||
In this example, whenever a POST request is made to https://yourserver.com/webhook, the respond function is triggered. This function prints the JSON payload of the request and returns a success status. The JSON payload is the data sent by the application that triggered the webhook. This could be any data related to the event that occurred in the other application. For instance, if the webhook was triggered by a new user signing up, the JSON payload might contain the new user’s details. | |||
You can use the curl command to send a POST request to your local server. Here’s an example: | |||
{{Pre}} | |||
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://localhost:5000/webhook | |||
</pre> | |||
= Modularize your shiny apps = | = Modularize your shiny apps = | ||
https://www.r-exercises.com/2018/10/15/modularize-your-shiny-apps-exercises/ | * https://shiny.rstudio.com/articles/modules.html | ||
* https://www.r-exercises.com/2018/10/15/modularize-your-shiny-apps-exercises/ | |||
* [https://appsilon.com/how-to-safely-remove-a-dynamic-shiny-module/ How to Safely Remove a Dynamic Shiny Module] | |||
= [http://withr.me/a-shiny-app-serves-as-shiny-server-load-balancer/ A Shiny-app Serves as Shiny-server Load Balancer] = | = [http://withr.me/a-shiny-app-serves-as-shiny-server-load-balancer/ A Shiny-app Serves as Shiny-server Load Balancer] = | ||
== ggtips: adding tooltips boxes to ggplots == | |||
[https://github.com/Roche/ggtips Adds interactive tooltip boxes to ggplots (standalone or rendered in Shiny)] | |||
= [https://github.com/rstudio/shinyloadtest Shinyloadtest] tools for load testing Shiny applications = | = [https://github.com/rstudio/shinyloadtest Shinyloadtest] tools for load testing Shiny applications = | ||
Line 293: | Line 768: | ||
= [http://withr.me/shiny-server-system-monitoring-for-open-source-edition/ Shiny-server System Performance Monitoring for Open Source Edition] = | = [http://withr.me/shiny-server-system-monitoring-for-open-source-edition/ Shiny-server System Performance Monitoring for Open Source Edition] = | ||
= Build a static website with R Shiny = | |||
[https://www.gl-li.com/2020/04/13/build-static-website-with-r-shiny/ Build a static website with R Shiny] | |||
= Embed a shiny app on your website = | |||
* https://support.rstudio.com/hc/en-us/articles/217592607-Can-I-embed-shiny-apps-in-other-websites-e-g-iFrames- | |||
* [https://datasciencegenie.com/how-to-embed-a-shiny-app-on-website/ How to embed a Shiny App on Website] | |||
* See this example [https://datavoreconsulting.com/post/interactive-visualization-survival-curves-shiny/ Interactive visualization of survival curves with Shiny] where it use '''iframe''' to embed a shiny app hosted on shinyapps.io. | |||
<iframe width="750" height="650" scrolling="no" frameborder="no" src="https://hinkelman.shinyapps.io/shiny-survival-covariate/"> | |||
</iframe> | |||
= Machine learning examples = | |||
[https://predictivehacks.com/how-to-share-your-machine-learning-models-with-shiny/ How To Share Your Machine Learning Models With Shiny] | |||
= Real Shiny Examples = | = Real Shiny Examples = | ||
* [https://discover.nci.nih.gov/cellminercdb/ CellMinerDB] from NCI/NIH. | * [https://discover.nci.nih.gov/cellminercdb/ CellMinerDB] from NCI/NIH. | ||
* [https://github.com/openbiox/UCSCXenaShiny UCSCXenaShiny] | |||
* [http://www.biosoft.hacettepe.edu.tr/voomDDA/ voomDDA]: Discovery of Diagnostic Biomarkers and Classification of RNA-Seq Data. https://peerj.com/articles/3890/ | * [http://www.biosoft.hacettepe.edu.tr/voomDDA/ voomDDA]: Discovery of Diagnostic Biomarkers and Classification of RNA-Seq Data. https://peerj.com/articles/3890/ | ||
* [https://github.com/fbreitwieser/pavian Interactive analysis of metagenomics data] | * [https://github.com/fbreitwieser/pavian Interactive analysis of metagenomics data] | ||
Line 302: | Line 792: | ||
* [https://whcsu.shinyapps.io/SurvELM/ SurvELM]: An R package for high dimensional survival analysis with extreme learning machine , [https://www.sciencedirect.com/science/article/abs/pii/S0950705118303447 paper] | * [https://whcsu.shinyapps.io/SurvELM/ SurvELM]: An R package for high dimensional survival analysis with extreme learning machine , [https://www.sciencedirect.com/science/article/abs/pii/S0950705118303447 paper] | ||
* Essential guidelines for computational method benchmarking [https://genomebiology.biomedcentral.com/articles/10.1186/s13059-019-1738-8 paper] | * Essential guidelines for computational method benchmarking [https://genomebiology.biomedcentral.com/articles/10.1186/s13059-019-1738-8 paper] | ||
* [https://www.rna-seqblog.com/bisr-rnaseq-an-efficient-and-scalable-rnaseq-analysis-workflow-with-interactive-report-generation/ BISR-RNAseq] – an efficient and scalable RNAseq analysis workflow with interactive report generation | |||
* [https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-023-05420-y ROGUE: an R Shiny app for RNA sequencing analysis and biomarker discovery] 2023 | |||
* [https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-020-03577-4 NASQAR]: a web-based platform for high-throughput sequencing data analysis and visualization. 2020 | |||
* [https://oncogenomics.bmc.lu.se/MutationExplorer/ MutationExplorer] (sloww) and [https://github.com/cbrueffer/MutationExplorer Source] | |||
* [https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-020-03819-5 ideal]: an R/Bioconductor package for interactive differential expression analysis | |||
* [https://github.com/dbdimitrov/BingleSeq/ BingleSeq]- A user-friendly R package for Bulk and Single-cell RNA-Seq data analyses. | |||
* [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7821039/ OmicsVolcano]: software for intuitive visualization and interactive exploration of high-throughput biological data | |||
* [https://sc1.engr.uconn.edu/ SC1: scRNA-Seq Analysis Pipeline], [https://www.biorxiv.org/content/10.1101/2021.03.19.435534v1 manuscript] | |||
* [https://github.com/satijalab/azimuth Azimuth] A Shiny web app for mapping datasets using Seurat v4 | |||
* [https://github.com/jamesdalg/CNVScope cnvscope.nci.nih.gov] | |||
* [https://appsilon.com/r-shiny-in-life-sciences-examples/ R Shiny in Life Sciences – Top 7 Dashboard Examples] | |||
* [https://appsilon.com/r-shiny-in-government-examples/ R Shiny in Government – Top 7 Dashboards You Should See] | |||
* [https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-022-04641-x classifieR a flexible interactive cloud-application for functional annotation of cancer transcriptomes] | |||
* [https://www.bioconductor.org/packages/release/bioc/html/BatchQC.html BatchQC] package. Batch Effects Quality Control Software. That's why the vignettes do not show any text/plots output. However, an HTML report and other files are created automatically in the working directory. | |||
* [http://bioconductor.org/packages/release/bioc/html/TCGAbiolinksGUI.html TCGAbiolinksGUI]: A Graphical User Interface to analyze cancer molecular and clinical data (got some error when calling TCGAbiolinksGUI()). [https://bioconductor.org/packages/release/bioc/vignettes/TCGAbiolinks/inst/doc/gui.html#Setting_up_image_using_command-line Docker image] with instruction (works fine 8GB image, access via http://URL:3334). | |||
** The web interface allows us to download the data and then upload it (from the docker machine) to the portal for data analysis. Very nice! | |||
** After uploading the data, the screen flashed many times? It should has a feedback to show the first few rows of the data. | |||
** Strangely even the downloaded csv file has required column names (days_to_death, days_to_last_follow_up, vital_status) for the analysis tool (the survival plot), I still got an error. ''An error has occurred. Check your logs or contact the app author for clarification.'' | |||
** No any error messages in the docker log. | |||
** It seems the performance & reliability is an issue. | |||
* [https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-023-05221-3 LACE 2.0]: an interactive R tool for the inference and visualization of longitudinal cancer evolution 2023 | |||
* [https://github.com/SomaLogic/ProViz ProViz] ProViz imports an ADAT file (SomaLogic's data file format) and allows users to perform various exploratory data analytic processes. | |||
= Interesting Examples = | = Interesting Examples = | ||
Line 307: | Line 819: | ||
* [https://medium.com/@zappingseb/very-shiny-holidays-5ee316fc7f84 Very shiny holidays!] Shiny + JQuery + CSS. | * [https://medium.com/@zappingseb/very-shiny-holidays-5ee316fc7f84 Very shiny holidays!] Shiny + JQuery + CSS. | ||
* [http://www.datasurg.net/2018/12/07/shinyfit-advanced-regression-modelling-in-a-shiny-app/ Shinyfit: Advanced regression modelling in a shiny app] | * [http://www.datasurg.net/2018/12/07/shinyfit-advanced-regression-modelling-in-a-shiny-app/ Shinyfit: Advanced regression modelling in a shiny app] | ||
* [https://github.com/leandrosev/Probability_Calculator_ShinyApp Probability Calculator App] | |||
* [https://blog.rsquaredacademy.com/introducting-vistributions/ Visually explore Probability Distributions with vistributions] | * [https://blog.rsquaredacademy.com/introducting-vistributions/ Visually explore Probability Distributions with vistributions] | ||
* https://github.com/hadley/cran-downloads <syntaxhighlight lang='rsplus'> | * https://github.com/hadley/cran-downloads <syntaxhighlight lang='rsplus'> | ||
Line 319: | Line 832: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* [http://lin-techdet.blogspot.com/2019/05/exploring-nginx-workers-load-arbitration.html Exploring Nginx workers load arbitration] | * [http://lin-techdet.blogspot.com/2019/05/exploring-nginx-workers-load-arbitration.html Exploring Nginx workers load arbitration] | ||
* COVID-19 | |||
** [https://github.com/seandavi/sars2pack sars2pack] | |||
** [https://github.com/gexijin/wuhan Coronavirus COVID-19 statistics and forecast] | |||
** https://github.com/nytimes/covid-19-data | |||
** [https://github.com/joachim-gassen/tidycovid19 tidycovid19], [https://joachim-gassen.github.io/2020/04/covid19-explore-your-visualier-dof/ Covid-19: Explore Your Visualizer Degrees of Freedom] | |||
** [https://mentalbreaks.rbind.io/posts/covid-19-tracker/ COVID-19 Tracker: Days since N] | |||
** [https://covid19.healthdata.org/projections Projections] (not shiny) | |||
** https://twitter.com/rafalab/status/1249704266480181250?s=20 (not shiny) | |||
** [https://ihmeuw-msca.github.io/CurveFit/methods/ IMHE COVID-19 CurveFit program], [http://taichivideos.org/t-t-liang-performs-two-person-san-shou/ "severe error" in the formulation of the IHME model] (not shiny) | |||
* [https://www.statsandr.com/blog/how-to-create-a-simple-coronavirus-dashboard-specific-to-your-country-in-r/ How to create a simple Coronavirus dashboard specific to your country in R] | |||
* [https://github.com/senthilthyagarajan/whatscooking Whats Cooking ??] | |||
* [https://apps.garrickadenbuie.com/countdown/ countdown], [https://github.com/gadenbuie/countdown source] | |||
* [https://blog.rstudio.com/2020/07/13/winners-of-the-2nd-shiny-contest/ Hangman] from 2nd Annual Shiny Contest. | |||
* [https://statisticaloddsandends.wordpress.com/2020/12/22/a-shiny-app-for-exploratory-data-analysis/ A shiny app for exploratory data analysis] | |||
* [https://www.biorxiv.org/content/10.1101/2023.06.09.544161v1 PlotS]: web-based application for data visualization and analysis | |||
* [https://c4tb.github.io/shinyExprPortal/ shinyExprPortal]. Deploy interactive Shiny portals for exploration and showcase of analysis of molecular expression and phenotype data using a configuration file. | |||
* Games | |||
** [https://pacha.dev/blog/2024/05/10/index.html If Doom runs everywhere, it must run on Shiny] | |||
= Scaling = | = Scaling = | ||
* [https://blog.rstudio.com/2018/06/26/shiny-1-1-0/ Shiny 1.1.0: Scaling Shiny with async] | * [https://blog.rstudio.com/2018/06/26/shiny-1-1-0/ Shiny 1.1.0: Scaling Shiny with async] | ||
= Long run with Shiny = | |||
* [https://www.r-bloggers.com/2018/07/long-running-tasks-with-shiny-challenges-and-solutions/ Long Running Tasks With Shiny: Challenges and Solutions] | |||
* [https://shiny.rstudio.com/articles/progress.html Progress indicators] | |||
* [https://stackoverflow.com/questions/26004302/how-to-display-a-busy-indicator-in-a-shiny-app How to display a busy indicator in a shiny app?] | |||
* [https://cran.r-project.org/web/packages/shinycssloaders/index.html shinycssloaders] package. Add a loading animation ("spinner") to outputs. Easy to use. | |||
** [https://stackoverflow.com/a/49488972 How to show Spinning Wheel or Busy Icon while waiting in Shiny] | |||
= Track Shiny App User Activity With the RStudio Connect Server == | |||
[https://www.rstudio.com/blog/track-shiny-app-use-server-api/ Track Shiny App User Activity With the RStudio Connect Server API] | |||
= Standalone application = | |||
[http://www.user2019.fr/static/pres/lt257916.pdf Photon: Building an Electron-Shiny app using a simple RStudio addin] | |||
= Mobile = | |||
[https://rinterface.github.io/shinyMobile shinyMobile] |
Latest revision as of 12:02, 18 October 2024
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 188 shiny-examples (note this is not what runExample("08_html") used. runExample() used local files that contain only 11 examples). The local directory is /Library/Frameworks/R.framework/Versions/4.2/Resources/library/shiny/ for R 4.2.x on macOS.
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.
Resources
- Mastering shiny Hadley Wickham
- Interactive web-based data visualization with R, plotly, and shiny Carson Sievert 2019
- Shiny Production with AWS Book by Matt Dancho
- The Best Resources for Learning Shiny App Development
- Top 7 Best R Shiny Books and Courses That Are Completely Free
- Level Up Your R/Shiny Team Skills with Our Free Ebook
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.
How to run an R shiny app
- Building Shiny apps – an interactive tutorial by Dean Attali
- Different ways:
- Click "Run App" in RStudio
- Call shiny::runApp(shinyApp(ui=ui, server=server, options = list(port = 3838))
- Call shiny::runApp("~/Directory") in your R console. This also works if we replaced a directory with an R file.
- R -e "shiny::runApp('~/shinyapp')" from a terminal
- An example of "app.R". Edit a table via the "DT" package.
- Turn a shiny application into a tablet or desktop app
rmarkdown::run() instead of rmarkdown::render()
Use rmarkdown::run("XXX.Rmd") file. If you use the render() function, you will receive an error "Error: path for html_dependency not provided Execution".
RInno
Installs shiny apps packaged as stand-alone Electron apps using Inno Setup, an open source software that builds installers for Windows programs only.
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 Github Pages: shinylive
- https://posit-dev.github.io/r-shinylive/
- Shinylive Code Editor https://shinylive.io/r/editor/
- CRAN (not the latest)
- Github (latest)
- {shinylive}: Serverless Shiny Apps
- The backend WebR - R in the Browser (not an R package).
- https://shiny.posit.co/py/docs/shinylive.html Shinylive for Python and Github
- Deploying flexdashboard on Github Pages with Docker and Github Actions 2022
- Deploy Shinylive R App on Github Pages and the post on Medium, 2023/9/26.
- It has good links to RStudio/Posit conf about shinylive
- VScode & a dockerized environment
- Add shiny in quarto blog with shinylive 2024/3/10. Suppose we have a file app.R in ~/Documents/shinylive folder.
- Install shinylive
# install.packages("pak") > pak::pak("posit-dev/r-shinylive") > packageVersion("shinylive") [1] ‘0.1.1.9000’
- Method 1: shinylive via web page. Just one line is need. It will output the local URL. My testing page on Github. To put it on github, go to the repository's setting page (make sure the repository is public). Click on "Pages" on LHS. In the Branch, select "main" branch and "/root" directory.
> shinylive::export('~/Documents/shinylive', '~/Documents/shinylive_out') ... Run the following in an R session to serve the app: httpuv::runStaticServer("~/Documents/shinylive_out") > httpuv::runStaticServer("~/Documents/shinylive_out") Serving: '~/Documents/shinylive_out' View at: http://127.0.0.1:7446 Press Esc or Ctrl + C to stop the server
- Method 2: embed shinylive in Quarto blog. Need to install Shinylive Quarto extension
quarto add quarto-ext/shinylive
- After that, modify the yaml of your index.qmd and put the contents of the app.R in a code chunk.
Deploy to Digital Ocean
How to deploy Shiny application to Digital Ocean using GitHub Actions
Deploy on shinyapps.io: rsconnect package
About the account
- Getting started with shinyapps.io page and Dashboard page.
- Limitations of the free account (5 applications, 25 active hours per month) on shinyapps.io.
- How Many Shiny Apps Can You Host for Free?
- Deploy to Shinyapps.io from Github Actions
- Push Button Publishing for Shiny Apps
Shinyapps.io can accept google account to sign up.
https://taichimd.shinyapps.io/stock/ (quantmod, ggplot2, reshape2, magrittr, rvest packages were used)https://taichimd.shinyapps.io/tspgov (ggplot2, reshape2, magrittr, rvest, plotly), Performance- https://shiny.taichimd.us/shiny-examples.html 188 shiny examples. source code for this HTML
- https://taichimd.shinyapps.io/Lasso_Simulation/ Lasso with simulated data
- https://taichimd.shinyapps.io/shinysurvival/ Kaplan-Meier curves plotter
- https://taichimd.shinyapps.io/cran-downloads/ (a backup copy of hadley shiny app). Some packages to test:
- ggpubr, survminer, GGally, glmnet, survAUC
- glmnet, SGL, MSGLasso, grplasso, biospear
- dockerfiler, stevedore, babelwhale, liftr
Note:
- Default System Packages.
- Two commands are needed to upload an app:
- rsconnect::setAccountInfo() [the full command is copied from account's token page.
- rsconnect::deployApp() [assume we are in the right working directory]. If the machine contains several accounts, we can use deployApp(account = "XXXX") to specify the account we want to deploy the app. After successful deployment, the browser will open the URL for our app.
- 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. But it seems this file/folder does not contain any secret information. So not worry.
- The rsconnect stores account information. If we get the app from another account make sure to delete this subfolder before we run rsconnect::deployApp(); otherwise we will get an error message Error: HTTP 403 .... Forbidden'; see I can't deploy my app with a name that was used in a previous deleted app.
- 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 R packages → packrat for more about packrat.
Caveats:
- I cannot upload my shiny app shinySurvival when it contains data in a subdirectory.
- When the app is running perfectly locally, it gives some errors when it is deployed to the shinyapps.io. Looking at the app log does not help too much.
deployApp()
- Choose which files ignored deploy to shinyapps.io. See Deploy to Shinyapps.io from Github Actions
deployApp(, appFiles= c("app.R" #, you can specify which files to deploy, #or keep this NULL to deploy everything ), appName = error_on_missing_name("MASTERNAME"), appTitle = "shinyapplication")
Packages
- 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 and Using your R packages in the cloud.
- When you deploy your application, the rsconnect package detects the packages that your application uses by looking for explicit library() calls within your application. Be aware that you should not have an explicit install.packages() call within your ui.R or server.R files.
- Currently the shinyapps.io service supports deploying packages installed from CRAN, GitHub, and BioConductor.
- rsconnect::appDependencies() - Recursively detect all package dependencies for an application.
- Error when trying to deploy to shinyapps.io: Application depends on package "package" but it is not. You have to fool the shinyapps (or rsconnect) package a bit so that it does not detect package as a literal package name.
do.call(library, list(package = package, character.only = TRUE))
- How to specify package versions when deploying Shiny app to shinyapps.io? See the next item.
- Shiny app which depends on package on GitHub? You should not install packages inside your shiny app, just install it locally and rsconnect will figure out how to install it based on your local library, you just have to load the library inside your app. Remember packageDescription() records all information even a package installed from a specific commit from Github repository.
- (Is this outdated?) In order for BioConductor packages to install succesfully on shinyapps.io, the repos option must be configured, either directly or by using setRepositories(), to include the BioConductor repositories in addition to CRAN. setRepositories()
setRepositories(addURLs = c(BioC = "https://bioconductor.org/packages/3.8/bioc"))
- Deploy shiny app using custom package. Also use renv or packrat package.
- How to manage R package dependencies for shiny app deployment (docker) packrat
- Deploying packrat projects to Shiny Server Pro packrat
- Building Web Apps with R Shiny ebook
- Deploy to Shinyapps.io from Github Actions
Deploying a development version of a shiny app
rsconnect::deployApp(..., appName="MyApp") rsconnect::deployApp(..., appName="MyApp_dev")
Shiny server installation
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.
Release
Shiny Server 1.5.16 Update 2021-01-03
Ubuntu & firewall
- In my case, I need to modify the firewall to allow traffic through to Shiny Server sudo ufw allow 3838. See How to Set Up Shiny Server on Ubuntu 16.04. The tutorial also covers Securing Shiny Server with a Reverse Proxy and SSL Certificate.
- Deploy your own Shiny app server with debian 2023-1
RHEL/CentOS 7
https://www.vultr.com/docs/how-to-install-shiny-server-on-centos-7
Raspberry Pi
- Automatically installing Shiny and RStudio server on Raspberry Pi OS with Ansible 2021-01-13
- 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
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
Google analytics
https://docs.rstudio.com/shiny-server/#google-analytics
Reverse proxy: Deploy your own shiny server
- http://qualityandinnovation.com/2015/12/09/deploying-your-very-own-shiny-server/
- Set up Apache(Nginx or another webserver) to act as a proxy to Shiny Server
- Setting up RStudio Server, Shiny Server and PostgreSQL
- When used with cloudflare, we should disable HTTP proxy (CDN) and use DNS only.
- How to make your home Shiny or Rstudio Server accessible from the public internet
Shiny https: Securing Shiny Open Source with SSL
Securing Shiny Server with Caddy
Shiny for Python
Shiny Assistant
Simplifying Parts Of A Shiny App by Creating Functions
Simplifying Parts Of A Shiny App by Creating Functions
shinyuieditor
shinyuieditor package
Shiny UI Prototype Builder
designer package
How to Build a Data Analysis App in R Shiny
How to Build a Data Analysis App in R Shiny
Landing page
- We can create an HTML file in /srv/shiny-server directory as the landing page where each app is under a sub-directory.
- R Shiny Apps by Sharon Machlis
- shinyLP package. Bootstrap Landing Home Pages for Shiny Applications
- Host a directory of applications from Shiny Server Professional v1.5.17 Administrator's Guide
The R Shiny packages you need for your web apps
https://www.r-bloggers.com/2017/07/the-r-shiny-packages-you-need-for-your-web-apps/
Other web apps
Ten simple rules for researchers who want to develop web apps
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)
- How To Dockerize ShinyApps + renv package
- Deploying an R Shiny App With Docker
- Running a shiny app in a docker container
- Dockerized Shiny Apps with Dependencies. renv
- Host Shiny Apps with Docker
- Using systemd to Run Shiny Apps
- Running Shiny Server in Docker
- Shiny Apps with Docker Compose, Part 1: Development 2021
- UCSCXenaShiny: An R package for interactively exploring UCSC Xena
- Automating Dockerfile creation for Shiny apps 2022/10/20
- R Shiny Docker: How To Run Shiny Apps in a Docker Container 2023/11/28
Dashboard
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 (using shiny, highcharter, viridisLite, ...)
- https://rmarkdown.rstudio.com/flexdashboard/
- Introducing flexdashboards. The gauge component is cool.
- Real example containing gauges https://gallery.shinyapps.io/cran-gauge/
- Automated Dashboard for Classification Neural Network in R
- Automated Dashboard with various correlation visualizations in R
- Speeding up R Plotly web apps - R x Javascript part I
shinyalert: create pretty popup messages (modals) in Shiny
shinyjs
Dash bio for R
Theme
shinytheme
bslib
R Shiny bslib – How to Work With Bootstrap Themes in Shiny
bootstraplib
How to use bootstraplib's Live Theme Previewer to customize Shiny apps?
shiny + databases
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
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
git clone https://github.com/rstudio/shiny-examples.git shiny::runApp("~/github/shiny-examples/018-datatable-options/")
- Shiny User Showcase
- Introducing Shiny App Stories
- 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
- geneSurv : 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/
multiple outputs to mainPanel
https://stackoverflow.com/a/27383312. Or use fluidRow() to expand the output in one tabPanel.
ui <- navbarPage("My App", tabPanel("Lasso", sidebarLayout( sidebarPanel( ... ), mainPanel( tabsetPanel( tabPanel("CV plot", plotOutput("plotLasso")), tabPanel("Lasso fitting", #verbatimTextOutput("fitLasso")) fluidRow( column(12, TextOutput("fitLasso", inline=T)), column(12, verbatimTextOutput("fitLasso2")) )) ) ) # close mainPanel ) # close sidebarLayout ), # close tabPanel Lasso ) #close navbar page server <- function(input, output, session) { output$fitLasso <- renderText({ }) output$fitLasso2 <- renderPrint({ }) } shinyApp(ui, server)
How to get the selected Tab-ID in a navbarPage with modules
HTML
- Customize your UI with HTML
# adding the new div tag to the sidebar tags$div(class="header", checked=NA, tags$p("Ready to take the Shiny tutorial? If so"), tags$a(href="shiny.rstudio.com/tutorial", "Click Here!")
- Build your entire UI with HTML. This seems to be a more complicated approach at first glance.
<application-dir> |-- app.R |-- www |-- index.html
and "app.R"
# ui is defined in the HTML file server <- function(input, output) { } shinyApp(ui = htmlTemplate("www/index.html"), server)
- HTML templates
- Shiny HTML Tags Glossary
Conditional input
Upload a file/files
- https://shiny.rstudio.com/articles/upload.html. fileInput(), renderTable(), tableOutput(). Add options(shiny.maxRequestSize = 30*1024^2) to increase the upload size to eg 30MB.
- how to upload and access multiple CSV files in R Shiny, source code. renderTable(), renderPrint(), renderUI().
- demo upload a zip file and unzip it to local machine. Source code. observeEvent()
- CASAS: Cancer Survival Analysis Suite, a web based application
- fileInput "accept" not filtering options. The RStudio built in web browser does not use the accept attribute. It will always show "All Files (*)" if you view your shiny app through RStudio. The RStudio built in web browser does not use the accept attribute. It will always show "All Files (*)" if you view your shiny app through RStudio.
reactive
- Lesson 4 Display reactive output
- Reactivity - An overview
- ?reactive, Lesson 6 Use reactive expressions
- 3 Basic reactivity from Mastering Shiny
- Shiny Reactivity Tricks, pt. II: Reactives Factories
actionButton and isolate
- https://shiny.rstudio.com/articles/isolation.html
- 049-isolate-demo
- It seems isolate() will always run the code one time. So consider eventReactive() or observeEvent() instead.
actionButton and eventReactive*
R Shiny App Tutorial | eventReactive() demo | Create dependency on actionButton
actionButton, observeEvent and reactiveValues
- ?reactiveValues
- Based on the following 2 examples. It seems
- reactiveValues() and observeEvent() work together.
- reactiveValues() will create a global variable and its value will be changed based on an actionButton.
- the effect of observeEvent() + reactiveValues() is similar to eventReactive() if we don't consider the situation that the new value depends on the old value.
- reactiveValues example
text_reactive <- reactiveValues( text = "No text has been submitted yet." ) observeEvent(input$submit, { text_reactive$text <- input$user_text }) output$text <- renderText({ text_reactive$text })
eventReactive() way:
text <- eventReactive(input$submit, { input$user_text }) output$text <- renderText({ text() })
- reactiveValues() in R Shiny - Example 1 - A counter (video)
counter <- reactiveValues(countervalue = 0) observeEvent(input$add1, counter$countervalue <- counter$countervalue + 1 output$counter <- renderText({ counter$countervalue })
The following code will break (Error in : C stack usage 7969216 is too close to the limit). So this is the case eventReactive() can't replace reactiveValues()!
countervalue <- eventReactive(input$add1, { countervalue() + 1 }) output$counter <- renderText({ countervalue() })
Dynamic UI
- Build a dynamic UI that reacts to user input. reactive(), observeEvent()
- Dynamically generated user interface components
- Dynamic UI in Shiny (incl. demo app) complicated!
- Youtube
- R Shiny app tutorial # 13 a - how to use renderUI() and uiOutput() in shiny - Dynamic input widgets
- (R Shiny Basic App) #8 Dynamically create Drop Down List source code in github. Code is short. reactive(), observe(), selectInput(), updateSelectInput().
eventReactive()
- 028-actionbutton-demo actionButton() and eventReactive()
- Using Action and Reset Buttons actionButton(), reactiveValues(), observeEvent() and eventReactive()
- https://shiny.rstudio.com/reference/shiny/1.0.3/observeEvent.html
- observeEvent() and eventReactive() from Mastering Shiny
- Shiny: what is the difference between observeEvent and eventReactive?
- eventReactive(eventExpr, handlerExpr, ...) creates a reactive value that changes based on the eventExpr. It seems we do not care much about the returned value. handleExpr is like output$SOMETHING.
- observeEvent(eventExpr, valueExpr, ...) simply is triggered based on eventExpr. It returns a reactive expression object.
Files
shinyFiles
shinyFiles package. This package extends the functionality of shiny by providing an API for client side access to the server file system. As many shiny apps are run locally this is equivalent to accessing the filesystem of the users own computer, without the overhead of copying files to temporary locations that is tied to the use of fileInput().
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
- Polished is an R package that adds authentication and user administration to your Shiny apps.
Install all required R packages
http://padamson.github.io/r/shiny/2016/03/13/install-required-r-packages.html
Icons
- R Shiny & FontAwesome Icons – How to Use Them in Your Dashboards
- Image not showing R Shiny (displayed as broken)
- Put the png file in the www directory
- Put your R code in the app.R file and run it through runApp() or the Run App icon in RStudio. It does not work if we call it by shinyApp() function.
- Example
library(shiny) library(survival) ui <- fluidPage( titlePanel( title = tags$div(tags$img(src = "icon.png", height = "32px", width = "32px"), "Interactive Kaplan Meier Plot", style = "background-color: black; color: white; padding: 10px;")), sidebarLayout( sidebarPanel( radioButtons("survivalType", "Choose survival data type:", choices = list("Overall Survival" = "os", "Progression Free Survival" = "pfs"), selected = "os") ), mainPanel( plotOutput("kmPlot") ) ) )
How do I add a favicon to my Shiny app
Adding a favicon to your Shiny app can be done by placing the favicon file in the www directory of your Shiny app and then using the tags$link function in your UI to link to it. Here’s how you can do it:
- Place your favicon file (e.g., favicon.ico) in the www directory of your Shiny app.
- In your UI, add the following line inside the fluidPage or navbarPage function:
tags$head(tags$link(rel = "shortcut icon", href = "favicon.ico", type = "image/x-icon"))
- Here’s an example of how it might look in a Shiny app:
ui <- fluidPage( titlePanel("My Shiny App"), tags$head(tags$link(rel = "shortcut icon", href = "favicon.ico", type = "image/x-icon")), # Rest of your UI code... ) server <- function(input, output) { # Your server code... } shinyApp(ui = ui, server = server)
Websites to convert an image to a favicon:
Building a Shiny App as a Package
- https://rtask.thinkr.fr/blog/building-a-shiny-app-as-a-package/
- Framework for Shiny Apps in R Packages
Three R Shiny tricks to make your Shiny app shines (2/3): Semi-collapsible sidebar
Color picker
https://github.com/daattali/colourpicker
Simulations
Tables
- Announcing the 2020 RStudio Table Contest
- Edit datatables in R shiny app. It uses DT package.
- reactable
Multimedia
Math formula
shinyMatrix
- https://cran.r-project.org/web/packages/shinyMatrix/index.html shinyMatrix: Shiny Matrix Input Field]
- How to Use shinyMatrix and plotly Graphs as Inputs in a Shiny App
Tree
D3
- collapsible d3js trees
- d3po: R package for easy interactive D3 visualization with Shiny
Time series
CSS
Debug
- reactlog: Visually debug your reactivity issues
- Debugging Shiny applications
Talks
Shiny in production: Principles, practices, and tools - Joe Cheng 2019
Tips
Shiny tips & tricks for improving your apps and solving common problems by Dean Attali.
Adding a website
Adding a website next to your Shiny server
A Guide to Benchmarking Memory Usage
Maximizing Efficiency: A Guide to Benchmarking Memory Usage in Shiny Apps
Recreating a Shiny App with Flask
Recreating a Shiny App with Flask
Webhook
Flask, a popular web framework.
This example assumes that you have a server running at https://yourserver.com/webhook that is set up to receive POST requests.
from flask import Flask, request app = Flask(__name__) @app.route('/webhook', methods=['POST']) def respond(): print(request.json) return {'status': 'success'}, 200 if __name__ == '__main__': app.run(port=5000, debug=True)
In this example, whenever a POST request is made to https://yourserver.com/webhook, the respond function is triggered. This function prints the JSON payload of the request and returns a success status. The JSON payload is the data sent by the application that triggered the webhook. This could be any data related to the event that occurred in the other application. For instance, if the webhook was triggered by a new user signing up, the JSON payload might contain the new user’s details.
You can use the curl command to send a POST request to your local server. Here’s an example:
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://localhost:5000/webhook
Modularize your shiny apps
- https://shiny.rstudio.com/articles/modules.html
- https://www.r-exercises.com/2018/10/15/modularize-your-shiny-apps-exercises/
- How to Safely Remove a Dynamic Shiny Module
A Shiny-app Serves as Shiny-server Load Balancer
ggtips: adding tooltips boxes to ggplots
Adds interactive tooltip boxes to ggplots (standalone or rendered in Shiny)
Shinyloadtest tools for load testing Shiny applications
shinytest
Shiny-server System Performance Monitoring for Open Source Edition
Build a static website with R Shiny
Build a static website with R Shiny
Embed a shiny app on your website
- https://support.rstudio.com/hc/en-us/articles/217592607-Can-I-embed-shiny-apps-in-other-websites-e-g-iFrames-
- How to embed a Shiny App on Website
- See this example Interactive visualization of survival curves with Shiny where it use iframe to embed a shiny app hosted on shinyapps.io.
<iframe width="750" height="650" scrolling="no" frameborder="no" src="https://hinkelman.shinyapps.io/shiny-survival-covariate/"> </iframe>
Machine learning examples
How To Share Your Machine Learning Models With Shiny
Real Shiny Examples
- CellMinerDB from NCI/NIH.
- UCSCXenaShiny
- 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
- SurvELM: An R package for high dimensional survival analysis with extreme learning machine , paper
- Essential guidelines for computational method benchmarking paper
- BISR-RNAseq – an efficient and scalable RNAseq analysis workflow with interactive report generation
- ROGUE: an R Shiny app for RNA sequencing analysis and biomarker discovery 2023
- NASQAR: a web-based platform for high-throughput sequencing data analysis and visualization. 2020
- MutationExplorer (sloww) and Source
- ideal: an R/Bioconductor package for interactive differential expression analysis
- BingleSeq- A user-friendly R package for Bulk and Single-cell RNA-Seq data analyses.
- OmicsVolcano: software for intuitive visualization and interactive exploration of high-throughput biological data
- SC1: scRNA-Seq Analysis Pipeline, manuscript
- Azimuth A Shiny web app for mapping datasets using Seurat v4
- cnvscope.nci.nih.gov
- R Shiny in Life Sciences – Top 7 Dashboard Examples
- R Shiny in Government – Top 7 Dashboards You Should See
- classifieR a flexible interactive cloud-application for functional annotation of cancer transcriptomes
- BatchQC package. Batch Effects Quality Control Software. That's why the vignettes do not show any text/plots output. However, an HTML report and other files are created automatically in the working directory.
- TCGAbiolinksGUI: A Graphical User Interface to analyze cancer molecular and clinical data (got some error when calling TCGAbiolinksGUI()). Docker image with instruction (works fine 8GB image, access via http://URL:3334).
- The web interface allows us to download the data and then upload it (from the docker machine) to the portal for data analysis. Very nice!
- After uploading the data, the screen flashed many times? It should has a feedback to show the first few rows of the data.
- Strangely even the downloaded csv file has required column names (days_to_death, days_to_last_follow_up, vital_status) for the analysis tool (the survival plot), I still got an error. An error has occurred. Check your logs or contact the app author for clarification.
- No any error messages in the docker log.
- It seems the performance & reliability is an issue.
- LACE 2.0: an interactive R tool for the inference and visualization of longitudinal cancer evolution 2023
- ProViz ProViz imports an ADAT file (SomaLogic's data file format) and allows users to perform various exploratory data analytic processes.
Interesting Examples
- Convert a data frame to a mediawiki table
- Very shiny holidays! Shiny + JQuery + CSS.
- Shinyfit: Advanced regression modelling in a shiny app
- Probability Calculator App
- Visually explore Probability Distributions with vistributions
- https://github.com/hadley/cran-downloads
install.packages("cranlogs") install.packages("shiny") runGitHub("hadley", "cran-downloads") # cannot open URL 'https://github.com/cran-downloads/hadley/archive/master.tar.gz': # HTTP status was '404 Not Found' system("cd ~/github/; git clone https://github.com/hadley/cran-downloads.git") runApp("~/github/cran-downloads/")
- Exploring Nginx workers load arbitration
- COVID-19
- sars2pack
- Coronavirus COVID-19 statistics and forecast
- https://github.com/nytimes/covid-19-data
- tidycovid19, Covid-19: Explore Your Visualizer Degrees of Freedom
- COVID-19 Tracker: Days since N
- Projections (not shiny)
- https://twitter.com/rafalab/status/1249704266480181250?s=20 (not shiny)
- IMHE COVID-19 CurveFit program, "severe error" in the formulation of the IHME model (not shiny)
- How to create a simple Coronavirus dashboard specific to your country in R
- Whats Cooking ??
- countdown, source
- Hangman from 2nd Annual Shiny Contest.
- A shiny app for exploratory data analysis
- PlotS: web-based application for data visualization and analysis
- shinyExprPortal. Deploy interactive Shiny portals for exploration and showcase of analysis of molecular expression and phenotype data using a configuration file.
- Games
Scaling
Long run with Shiny
- Long Running Tasks With Shiny: Challenges and Solutions
- Progress indicators
- How to display a busy indicator in a shiny app?
- shinycssloaders package. Add a loading animation ("spinner") to outputs. Easy to use.
Track Shiny App User Activity With the RStudio Connect Server =
Track Shiny App User Activity With the RStudio Connect Server API
Standalone application
Photon: Building an Electron-Shiny app using a simple RStudio addin