Lokesh Mano
NBIS, SciLifeLab
14-Apr-2025
NS()
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [editor, viewer]
counter_ui <- function(id) {
ns <- NS(id)
div(
actionButton(ns("btn"), label = "Counter"),
textOutput(ns("txt"))
)
}
counter_server <- function(id) {
moduleServer(id, function(input, output, session) {
count <- reactiveVal(0)
output$txt <- renderText({
count(count() + 1)
paste0("Counter ", id, ":", count())
}) |> bindEvent(input$btn)
})
}
shinyApp(
ui = fluidPage(
counter_ui(id = "1"),
counter_ui(id = "2")
),
server = function(input, output, session) {
counter_server("1")
counter_server("2")
}
)
print()
statements
Interrupt execution and inspect environment browser()
Visualize relationships using reactlog
Assess compute and RAM usage using profvis
Simple profiling using shiny.tictoc
App launch
New user
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| viewerHeight: 650
webr::install("shinythemes")
shinyApp(
ui = fluidPage(
shinythemes::themeSelector(),
sidebarPanel(
textInput("txt", "Text input:", "text here"),
sliderInput("slider", "Slider input:", 1, 100, 30),
actionButton("action", "Button"),
actionButton("action2", "Button2", class = "btn-primary")
),
mainPanel(
tabsetPanel(
tabPanel("Tab 1"),
tabPanel("Tab 2")
)
)
),
server = function(input, output) {}
)
www/
---
title: "Interactive scatterplot"
format: html
server: shiny
---
```{r}
library(shiny)
library(ggplot2)
selectInput("x_var", "X-axis Variable:", choices=names(mtcars), selected = "hp"),
selectInput("y_var", "Y-axis Variable:", choices=names(mtcars), selected = "mpg"),
plotOutput("plot")
```
```{r}
#| context: server
output$plot <- renderPlot({
ggplot(mtcars, aes_string(x = input$x_var, y = input$y_var)) +
geom_point() +
labs(title = "Interactive mtcars scatterplot",
x = input$x_var,
y = input$y_var)
})
```
runtime: shiny
.---
title: Interactive document
output: html_document
runtime: shiny
---
<iframe>
<iframe src="https://user.shinyapps.io/app"></iframe>
Documentation
Books
Conferences
Blogs & Podcasts
Slide inspirations: Roy Francis (NBIS, RaukR2024)