Skip to content

Commit

Permalink
Deployed 8d6c450 with MkDocs version: 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 29, 2024
0 parents commit 1f0b90f
Show file tree
Hide file tree
Showing 337 changed files with 84,410 additions and 0 deletions.
Empty file added .nojekyll
Empty file.
494 changes: 494 additions & 0 deletions 404.html

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions R_code/exercises/01_calculator.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
library(shiny)

# Define UI
ui <- fluidPage(
titlePanel(""),

sidebarLayout(
sidebarPanel(
# input here
# check: https://shiny.posit.co/r/gallery/widgets/widget-gallery/
),

mainPanel(
# output here
# check: https://github.com/rstudio/cheatsheets/blob/main/shiny.pdf
)
)
)

# Define server logic
server <- function(input, output) {

output$result <- renderText({
num1 <- 2
num2 <- 1

result <- switch(input$operation,
"add" = num1 + num2,
"subtract" = num1 - num2,
"multiply" = num1 * num2,
"divide" = num1 / num2
)

paste("Result:", result)
})
}

# Run the application
shinyApp(ui = ui, server = server)
Binary file added R_code/misc/TipsTricks_Day1.pdf
Binary file not shown.
55 changes: 55 additions & 0 deletions R_code/misc/k_means_reactlog.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
library(shiny)
library(reactlog)

reactlog_enable()

ui <- function() {

# k-means only works with numerical variables,
# so don't give the user the option to select
# a categorical variable
vars <- setdiff(names(iris), "Species")

pageWithSidebar(
headerPanel('Iris k-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', vars),
selectInput('ycol', 'Y Variable', vars, selected = vars[[2]]),
numericInput('clusters', 'Cluster count', 3, min = 1, max = 9)
),
mainPanel(
plotOutput('plot1')
)
)}




server <- function(input, output, session) {

# Combine the selected variables into a new data frame
selectedData <- reactive({
iris[, c(input$xcol, input$ycol)]
})

clusters <- reactive({
kmeans(selectedData(), input$clusters)
})

output$plot1 <- renderPlot({
palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))

par(mar = c(5.1, 4.1, 0, 1))
plot(selectedData(),
col = clusters()$cluster,
pch = 20, cex = 3)
points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
})

}

shinyApp(ui = ui, server = server)

shiny::reactlogShow()

46 changes: 46 additions & 0 deletions R_code/solutions/01_calculator.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
library(shiny)

# Define UI
ui <- fluidPage(
titlePanel("Shiny Calculator"),

sidebarLayout(
sidebarPanel(
numericInput("num1", label = "Enter first number:", value = 0),
numericInput("num2", label = "Enter second number:", value = 0),
radioButtons("operation", label = "Choose operation:", choices = list(
"add",
"subtract",
"multiply",
"divide"
))
),

mainPanel(
textOutput("result")
)
)
)

# Define server logic
server <- function(input, output) {

output$result <- renderText({
if (input$operation == "divide") {
req(input$num2 != 0)
}

result <- switch(input$operation,
"add" = input$num1 + input$num2,
"subtract" = input$num1 - input$num2,
"multiply" = input$num1 * input$num2,
"divide" = input$num1 / input$num2
)

paste("Result:", result)
})

}

# Run the application
shinyApp(ui = ui, server = server)
52 changes: 52 additions & 0 deletions R_code/solutions/02_calculator_reactive.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
library(shiny)

# Define UI
ui <- fluidPage(
titlePanel("Shiny Calculator"),

sidebarLayout(
sidebarPanel(
numericInput("num1", label = "Enter first number:", value = 0),
numericInput("num2", label = "Enter second number:", value = 0),
radioButtons("operation", label = "Choose operation:", choices = list(
"add",
"subtract",
"multiply",
"divide"
))
),

mainPanel(
textOutput("result")
)
)
)

# Define server logic
server <- function(input, output) {

result <- reactive({
# Handling division by zero with req()
if (input$operation == "divide") {
req(input$num2 != 0)
}

switch(input$operation,
"add" = input$num1 + input$num2,
"subtract" = input$num1 - input$num2,
"multiply" = input$num1 * input$num2,
"divide" = input$num1 / input$num2
)
})

print(input$num1)
# print(result())

output$result <- renderText({
paste("Result:", result())
})

}

# Run the application
shinyApp(ui = ui, server = server)
46 changes: 46 additions & 0 deletions R_code/solutions/03_day1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
library(shiny)
library(tidyverse)
library(ggbeeswarm)

data(iris)

# Define UI
ui <- fluidPage(
titlePanel("My Shiny App"),
sidebarLayout(
sidebarPanel(
sliderInput("dotsize", label = "Dot Size", min = 0.1, max = 5, value = 1, step = 0.1),
downloadButton(
outputId = 'save_violinplot',
label = 'Save plot',
icon = shiny::icon('download')
)
),
mainPanel(
plotOutput("plot")
)
)
)

# Define server logic
server <- function(input, output) {
violinplot <- reactive({
ggplot(iris, aes(x=Species, y=Petal.Length)) +
geom_violin(aes(fill=Species)) +
geom_quasirandom(size=input$dotsize) +
geom_boxplot(width=0.1)
})

output$plot <- renderPlot({
violinplot()
})

output$save_violinplot <- downloadHandler(
filename = 'plot.pdf',
content = function(file) {
ggsave(file, plot=violinplot(), width=297, height=210, unit='mm')
})
}

# Run the application
shinyApp(ui = ui, server = server)
45 changes: 45 additions & 0 deletions R_code/solutions/04_shinydashboard.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
library(shiny)
library(shinydashboard)
library(tidyverse)
library(ggbeeswarm)

data(iris)

# Define UI
ui <- dashboardPage(
dashboardHeader(title = "My Shiny App"),
dashboardSidebar(
sliderInput("dotsize", label = "Dot Size", min = 0.1, max = 5, value = 1, step = 0.1),
downloadButton(
outputId = 'save_violinplot',
label = 'Save plot',
icon = shiny::icon('download')
)
),
dashboardBody(
plotOutput("plot")
)
)

# Define server logic
server <- function(input, output) {
violinplot <- reactive({
ggplot(iris, aes(x=Species, y=Petal.Length)) +
geom_violin(aes(fill=Species)) +
geom_quasirandom(size=input$dotsize) +
geom_boxplot(width=0.1)
})

output$plot <- renderPlot({
violinplot()
})

output$save_violinplot <- downloadHandler(
filename = 'plot.pdf',
content = function(file) {
ggsave(file, plot=violinplot(), width=297, height=210, unit='mm')
})
}

# Run the application
shinyApp(ui = ui, server = server)
50 changes: 50 additions & 0 deletions R_code/solutions/05_includeCSS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
library(shiny)
library(shinydashboard)
library(tidyverse)
library(ggbeeswarm)

data(iris)

# Define UI
ui <- dashboardPage(
dashboardHeader(
title = "My Shiny App"
),
dashboardSidebar(
sliderInput("dotsize", label = "Dot Size", min = 0.1, max = 5, value = 1, step = 0.1),
downloadButton(
outputId = 'save_violinplot',
label = 'Save plot',
icon = shiny::icon('download')
)
),
dashboardBody(
tags$head(
includeCSS('05_includeCSS.css')
),
plotOutput("plot")
)
)

# Define server logic
server <- function(input, output) {
violinplot <- reactive({
ggplot(iris, aes(x=Species, y=Petal.Length)) +
geom_violin(aes(fill=Species)) +
geom_quasirandom(size=input$dotsize) +
geom_boxplot(width=0.1)
})

output$plot <- renderPlot({
violinplot()
})

output$save_violinplot <- downloadHandler(
filename = 'plot.pdf',
content = function(file) {
ggsave(file, plot=violinplot(), width=297, height=210, unit='mm')
})
}

# Run the application
shinyApp(ui = ui, server = server)
4 changes: 4 additions & 0 deletions R_code/solutions/05_includeCSS.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aside .btn {
margin: 12px;
color: #000000 !important;
}
Loading

0 comments on commit 1f0b90f

Please sign in to comment.