Skip to content

Commit

Permalink
Shiny review edits, closes #305
Browse files Browse the repository at this point in the history
  • Loading branch information
mine-cetinkaya-rundel committed Jul 22, 2023
1 parent 36885c8 commit a15be3d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions _freeze/html/shiny/execute-results/html.json

Large diffs are not rendered by default.

Binary file modified html/images/logo-shiny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 24 additions & 19 deletions html/shiny.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ Users can manipulate the UI, which will cause the server to update the UI's disp
Save your template as `app.R`.
Keep your app in a directory along with optional extra files.

**app-name:** The directory name is the app name
- **app-name:** The directory name is the app name

```{=html}
<!-- -->
```
- **app.R**

- DESCRIPTION and README: (optional) used in showcase mode

- R/: (optional) directory of supplemental .R files that are sources automatically, must be named `R`
- R/: (optional) directory of supplemental .R files that are sourced automatically, must be named `R`

- www/: (optional) directory of giles to share with web browsers (images, CSS, .js, etc.), must be named `www`
- www/: (optional) directory of files to share with web browsers (images, CSS, .js, etc.), must be named `www`

Launch apps stored in a directory with `runApp(<path to directory>)`.

To generate the template, type `shinyApp` and press `Tab` in the RStudio IDE or go to **File \> New Project \> New Directory \> Shiny Web Applications**.
To generate the template, type `shinyApp` and press `Tab` in the RStudio IDE or go to **File \> New Project \> New Directory \> Shiny Application**.

```{r}
#| eval: false
Expand Down Expand Up @@ -118,7 +121,7 @@ Share your app in three ways:
: Table of render\*() functions and their associated \*Output() functions.

These are the core output types.
See [htmlwidgets.org](htmlwidgets.org) for many more options.
See [htmlwidgets.org](https://www.htmlwidgets.org/) for many more options.

## Inputs

Expand Down Expand Up @@ -151,17 +154,14 @@ Input values are **reactive**.

- `sliderInput(inputId, label, min, max, value, step, round, format, locale, ticks, animate, width, sep, pre, post, timeFormat, timezone, dragRange)`

- `submitButton(text, icon, width)`: Prevent reactions for entire app

- `textInput(inputId, label, value, width, placeholder)`: Also `textAreaInput()`

<!-- page 2 -->

## Reactivity

Reactive values work together with reactive functions.
Call a reactive value from within the arguments of one of these functions to avoid the error.
**Operation not allowed without an active reactive context.**
Call a reactive value from within the arguments of one of these functions to avoid the error `Operation not allowed without an active reactive context`**.**

![](images/reactivity-diagram.png){fig-align="center"}

Expand All @@ -177,7 +177,6 @@ Call a reactive value from within the arguments of one of these functions to avo
- `*Input()`
- Perform side effects
- `observeEvent()`

- `observe()`
- Schedule updates
- `invalidateLater()`
Expand All @@ -193,7 +192,7 @@ Call a reactive value from within the arguments of one of these functions to avo

### Create Your own Reactive Values

- `*Input()` functions: (see front page) Each input function creates a reactive value stored as input\$<inputId>.
- `*Input()` functions: Each input function creates a reactive value stored as `input$<inputId>`.

```{r}
#| eval: false
Expand All @@ -204,12 +203,14 @@ Call a reactive value from within the arguments of one of these functions to avo
)
```

- `reactiveValues(...)`: Creates a list of reactive values whose values you can set.
- `reactiveVal():` Creates a single reactive values object.

`reactiveValues(...)`: Creates a list of reactive values whose values you can set.

```{r}
#| eval: false
#reactiveValues example
# reactiveVal example
server <- function(input,output){
rv <- reactiveValues()
rv$number <- 5
Expand All @@ -228,7 +229,7 @@ Call a reactive value from within the arguments of one of these functions to avo

- notify dependencies when invalidated

Call the expression with function sytrax, e.g. `re()`.
Call the expression with function syntax, e.g. `re()`.

```{r}
#| eval: false
Expand All @@ -242,7 +243,8 @@ Call a reactive value from within the arguments of one of these functions to avo
server <- function(input,output){
re <- reactive({
paste(input$a,input$z)})
paste(input$a,input$z)
})
output$b <- renderText({
re()
})
Expand All @@ -268,7 +270,8 @@ Call a reactive value from within the arguments of one of these functions to avo
server <- function(input,output){
re <- eventReactive(
input$go,{input$a})
input$go,{input$a}
)
output$b <- renderText({
re()
})
Expand Down Expand Up @@ -303,8 +306,10 @@ Call a reactive value from within the arguments of one of these functions to avo

### Perform Side Effects

- `observe(x, env)`: Creates an observer from the given expression.

- `observeEvent(eventExpr, handlerExpr, event.env, event.quoted, handler.env, handler.quoted, ..., label, suspended, priority, domain, autoDestroy, ignoreNULL, ignoreInit, once)`: Runs code in 2nd argument when reactive values in 1st argument change.
See `observe()` for alternative.
Alternative to `observe``()`.

```{r}
#| eval: false
Expand Down Expand Up @@ -461,7 +466,7 @@ Other elements:
- `titlePanel()`
- `wellPanel()`

Organize panels and elements into a layout with a layour function.
Organize panels and elements into a layout with a layout function.
Add elements as arguments of the layout functions.

- `sidebarLayout()`
Expand Down Expand Up @@ -530,7 +535,7 @@ ui <- navbarPage(

## Themes

Use the **bslib** pacage to add existing themes to your Shiny app ui, or make your own.
Use the **bslib** package to add existing themes to your Shiny app ui, or make your own.

```{r}
#| eval: false
Expand Down
Binary file modified keynotes/shiny.key
Binary file not shown.
Binary file modified shiny.pdf
Binary file not shown.

0 comments on commit a15be3d

Please sign in to comment.