diff --git a/_freeze/mod_interactivity/execute-results/html.json b/_freeze/mod_interactivity/execute-results/html.json index 13457f0..63720bf 100644 --- a/_freeze/mod_interactivity/execute-results/html.json +++ b/_freeze/mod_interactivity/execute-results/html.json @@ -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 Research Coordination Networks 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- Define the three fundamental components of a Shiny app\n- Explain benefits and limitations of interactive approaches to data exploration\n- Generate an interactive app with Shiny\n- Use text formatting methods in a Shiny app\n- Explore available Shiny layout options\n- Create a Shiny app\n- Describe (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 deploy 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 Research Coordination Networks 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- Define the three fundamental components of a Shiny app\n- Explain benefits and limitations of interactive approaches to data exploration\n- Generate an interactive app with Shiny\n- Use text formatting methods in a Shiny app\n- Explore available Shiny layout options\n- Create a Shiny app\n- Describe (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 user interface (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 deploy 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" diff --git a/mod_interactivity.qmd b/mod_interactivity.qmd index 5fa5327..c115dc7 100644 --- a/mod_interactivity.qmd +++ b/mod_interactivity.qmd @@ -51,6 +51,32 @@ library(tidyverse) ## Shiny Fundamentals +All Shiny apps are composed of three pieces: a user interface (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