Skip to content

Commit

Permalink
Fleshed out basic (non-interactive) Shiny app topic
Browse files Browse the repository at this point in the history
  • Loading branch information
njlyon0 committed Apr 30, 2024
1 parent 9e7f008 commit b40486f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _freeze/mod_interactivity/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hash": "5877a40462e57c0565b899f1b0bfd7ba",
"hash": "8d196a28b7a549d155b92a7061392e37",
"result": {
"markdown": "---\ntitle: \"Creating Interactive Apps\"\ncode-annotations: hover\nexecute: \n eval: false\n---\n\n\n## Overview\n\nShiny is a popular tool that allows users to build interactive web applications without the normally pre-requisite web development expertise. In addition to Shiny apps being simpler to build for the programmer they are often used to allow visitors to perform coding tasks without ever actually writing code. These are huge advantages because they reduce or eliminate significant technical barriers in developing truly interactive applications.\n\nIn synthesis contexts, Shiny can be used for a variety of valuable purposes. You can use it to develop dashboards for sharing data with related communities, allow your team to quickly \"play with\" exploratory graphs, or even to create a data submission portal (as is the case with some <u>R</u>esearch <u>C</u>oordination <u>N</u>etworks or \"RCNs\").\n\nNote that Shiny can be built in either R or Python 'under the hood' but for the purposes of this module we'll focus on R.\n\n## Learning Objectives\n\nAfter completing this topic you will be able to: \n\n- <u>Define</u> the three fundamental components of a Shiny app\n- <u>Explain</u> benefits and limitations of interactive approaches to data exploration\n- <u>Generate</u> an interactive app with Shiny\n- <u>Use</u> text formatting methods in a Shiny app\n- <u>Explore</u> available Shiny layout options\n- <u>Create</u> a Shiny app\n- <u>Describe</u> (briefly) the purpose of deploying a Shiny app\n\n## Needed Packages\n\nIf you'd like to follow along with the code chunks included throughout this module, you'll need to install the following packages:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Note that these lines only need to be run once per computer\n## So you can skip this step if you've installed these before\ninstall.packages(\"tidyverse\")\ninstall.packages(\"shiny\")\ninstall.packages(\"htmltools\")\ninstall.packages(\"lterdatasampler\")\n```\n:::\n\n\nWe'll load the Tidyverse meta-package here to have access to many of its useful tools when we need them later.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Load tidyverse\nlibrary(tidyverse)\n```\n:::\n\n\n## Shiny Fundamentals\n\n\n\n## Including Data\n\n\n\n## Text Formatting\n\n\n\n## Layouts\n\n\n\n## Deployment\n\nWhen Shiny apps are only being used by those in your team, keeping them as a code script works well. However, if you'd like those outside of your team to be able to find your app as they would any other website you'll need to <u>deploy</u> your Shiny app. This process is outside of the scope of this module but is often the end goal of Shiny app development.\n\nTake a look at [Posit's instructions for deployment](https://shiny.posit.co/r/articles/share/deployment-web/) for more details but essentially \"deployment\" is the process of getting your local app hosted on shinyapps.io which gives it a link that anyone can use to access/run your app on their web browser of choice.\n\n## Additional Interactivity Resources\n\n### Papers & Documents\n\n- \n\n### Workshops & Courses\n\n- Posit's [Welcome to Shiny](https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html) (for R coders)\n- 2022 All Scientists' Meeting [Shiny Apps for Sharing Science](https://njlyon0.github.io/asm-2022_shiny-workshop/) workshop\n\n### Websites\n\n- Posit's [Shiny](https://shiny.posit.co/) website\n",
"markdown": "---\ntitle: \"Creating Interactive Apps\"\ncode-annotations: hover\nexecute: \n eval: false\n---\n\n\n## Overview\n\nShiny is a popular tool that allows users to build interactive web applications without the normally pre-requisite web development expertise. In addition to Shiny apps being simpler to build for the programmer they are often used to allow visitors to perform coding tasks without ever actually writing code. These are huge advantages because they reduce or eliminate significant technical barriers in developing truly interactive applications.\n\nIn synthesis contexts, Shiny can be used for a variety of valuable purposes. You can use it to develop dashboards for sharing data with related communities, allow your team to quickly \"play with\" exploratory graphs, or even to create a data submission portal (as is the case with some <u>R</u>esearch <u>C</u>oordination <u>N</u>etworks or \"RCNs\").\n\nNote that Shiny can be built in either R or Python 'under the hood' but for the purposes of this module we'll focus on R.\n\n## Learning Objectives\n\nAfter completing this topic you will be able to: \n\n- <u>Define</u> the three fundamental components of a Shiny app\n- <u>Explain</u> benefits and limitations of interactive approaches to data exploration\n- <u>Generate</u> an interactive app with Shiny\n- <u>Use</u> text formatting methods in a Shiny app\n- <u>Explore</u> available Shiny layout options\n- <u>Create</u> a Shiny app\n- <u>Describe</u> (briefly) the purpose of deploying a Shiny app\n\n## Needed Packages\n\nIf you'd like to follow along with the code chunks included throughout this module, you'll need to install the following packages:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Note that these lines only need to be run once per computer\n## So you can skip this step if you've installed these before\ninstall.packages(\"tidyverse\")\ninstall.packages(\"shiny\")\ninstall.packages(\"htmltools\")\ninstall.packages(\"lterdatasampler\")\n```\n:::\n\n\nWe'll load the Tidyverse meta-package here to have access to many of its useful tools when we need them later.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Load tidyverse\nlibrary(tidyverse)\n```\n:::\n\n\n## Shiny Fundamentals\n\nAll Shiny apps are composed of three pieces: a <u>u</u>ser <u>i</u>nterface (UI), a server, and a call to the `shinyApp` function. The user interface includes everything that the user sees and can interact with; note that this includes _both_ inputs and outputs. The server is responsible for all code operations performed on user inputs in order to generate outputs specified in the UI. The server is _not_ available to the user. Finally, the `shinyApp` function simply binds together the UI and server and creates a living app. The app appears either in your RStudio or in a new tab on a web browser depending on your settings.\n\nFor those of you who write your own functions, you may notice that the syntax of Shiny is **very** similar to the syntax of functions. If you have not already, your quality of life will benefit greatly if you turn on \"rainbow parentheses\" in RStudio (Tools {{< fa arrow-right >}} Global Options {{< fa arrow-right >}} Code {{< fa arrow-right >}} Display {{< fa arrow-right >}} Check \"Use rainbow parentheses\" box).\n\nLet's consider an artificially simple Shiny app so you can get a sense for the fundamental architecture of this tool.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Define the UI\nbasic_ui <- shiny::fluidPage( # <1>\n \"Hello there!\"\n)\n\n# Define the server\nbasic_server <- function(input, output){ } # <2>\n\n# Generate the app\nshiny::shinyApp(ui = basic_ui, server = basic_server)\n```\n:::\n\n1. The `fluidPage` function is important for leaving flexibility in UI layout which we'll explore later in the module\n2. Because this app has no inputs or outputs, it doesn't need anything in the 'server' component (though it still does require an empty server!)\n\nIf you copy and run the above code, you should see an app that is a blank white page with \"Hello there!\" written in the top left in plain text. Congratulations, you have now made your first Shiny app! Now, your reason for exploring this module likely involves an app that actually does something but the fundamental structure of all apps--even skeletal apps like this one--is the same. More complicated apps will certainly have more content in the UI and server sections but all Shiny apps will have this tripartite structure.\n\n## Interactive Apps\n\n\n\n\n## Including Data\n\n\n\n## Text Formatting\n\n\n\n## Layouts\n\n\n\n## Deployment\n\nWhen Shiny apps are only being used by those in your team, keeping them as a code script works well. However, if you'd like those outside of your team to be able to find your app as they would any other website you'll need to <u>deploy</u> your Shiny app. This process is outside of the scope of this module but is often the end goal of Shiny app development.\n\nTake a look at [Posit's instructions for deployment](https://shiny.posit.co/r/articles/share/deployment-web/) for more details but essentially \"deployment\" is the process of getting your local app hosted on shinyapps.io which gives it a link that anyone can use to access/run your app on their web browser of choice.\n\n## Additional Interactivity Resources\n\n### Papers & Documents\n\n- \n\n### Workshops & Courses\n\n- Posit's [Welcome to Shiny](https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html) (for R coders)\n- 2022 All Scientists' Meeting [Shiny Apps for Sharing Science](https://njlyon0.github.io/asm-2022_shiny-workshop/) workshop\n\n### Websites\n\n- Posit's [Shiny](https://shiny.posit.co/) website\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
Expand Down
26 changes: 26 additions & 0 deletions mod_interactivity.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ library(tidyverse)

## Shiny Fundamentals

All Shiny apps are composed of three pieces: a <u>u</u>ser <u>i</u>nterface (UI), a server, and a call to the `shinyApp` function. The user interface includes everything that the user sees and can interact with; note that this includes _both_ inputs and outputs. The server is responsible for all code operations performed on user inputs in order to generate outputs specified in the UI. The server is _not_ available to the user. Finally, the `shinyApp` function simply binds together the UI and server and creates a living app. The app appears either in your RStudio or in a new tab on a web browser depending on your settings.

For those of you who write your own functions, you may notice that the syntax of Shiny is **very** similar to the syntax of functions. If you have not already, your quality of life will benefit greatly if you turn on "rainbow parentheses" in RStudio (Tools {{< fa arrow-right >}} Global Options {{< fa arrow-right >}} Code {{< fa arrow-right >}} Display {{< fa arrow-right >}} Check "Use rainbow parentheses" box).

Let's consider an artificially simple Shiny app so you can get a sense for the fundamental architecture of this tool.

```{r basic-shiny}
# Define the UI
basic_ui <- shiny::fluidPage( # <1>
"Hello there!"
)
# Define the server
basic_server <- function(input, output){ } # <2>
# Generate the app
shiny::shinyApp(ui = basic_ui, server = basic_server)
```
1. The `fluidPage` function is important for leaving flexibility in UI layout which we'll explore later in the module
2. Because this app has no inputs or outputs, it doesn't need anything in the 'server' component (though it still does require an empty server!)

If you copy and run the above code, you should see an app that is a blank white page with "Hello there!" written in the top left in plain text. Congratulations, you have now made your first Shiny app! Now, your reason for exploring this module likely involves an app that actually does something but the fundamental structure of all apps--even skeletal apps like this one--is the same. More complicated apps will certainly have more content in the UI and server sections but all Shiny apps will have this tripartite structure.

## Interactive Apps




## Including Data
Expand Down

0 comments on commit b40486f

Please sign in to comment.