0% found this document useful (0 votes)
27 views

DR Fayaz Presentation

Uploaded by

Eric Sosa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

DR Fayaz Presentation

Uploaded by

Eric Sosa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 160

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/361151357

An Introduction to R-Shiny Project in R With an Examples in the


Functional Data Analysis (FDA) Related Packages Statfda &
refund.shiny

Presentation · June 2022


DOI: 10.13140/RG.2.2.29431.91043

CITATIONS READS

0 139

1 author:

Mohammad Fayaz
Allameh Tabataba'i University
49 PUBLICATIONS   250 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Comparing Functional Data analysis, Mixed Models and statistical learning methods in predicting Dichotomous outcome View project

The Functional Data Analysis with United Nations (UN) public Datasets View project

All content following this page was uploaded by Mohammad Fayaz on 07 June 2022.

The user has requested enhancement of the downloaded file.


An Introduction to R-Shiny Project in R
With an Examples in the
Functional Data Analysis (FDA)
Related Packages
Statfda & refund.shiny

Mohammad Fayaz,
PhD in Biostatistics

7 June 2022
20:00

1
2
Contents
• Literature Review
• Shiny R Package
• Examples
• First R Codes
• Shiny Cheat Sheet
• Free Online Books
• Shiny Commercials
• R/Bioconductor Shiny Packages
• R Markdown
• R Markdown Chet Sheet
• Case Studies: Functional Data Analysis
• COVID-19 in the World and Spain
• Statfda
• refund.shiny
• End 3
Literature Review

4
Literature Review

5
Literature Review

6
Literature Review

7
Literature Review

8
Literature Review

9
Literature Review

10
Literature Review

11
Literature Review

12
Literature Review

13
Literature Review

14
Literature Review

15
Literature Review

16
Shiny R Package

17
Shiny R Package

https://cran.r-project.org/web/packages/shiny/index.html

18
Shiny R Package

https://gallery.shinyapps.io/cran-explorer/?_ga=2.244504517.1711980662.1654351552-
1941896533.1653805620

19
Shiny R Package

https://gallery.shinyapps.io/cran-explorer/?_ga=2.244504517.1711980662.1654351552-
1941896533.1653805620

20
Shiny R Package

https://gallery.shinyapps.io/cran-explorer/?_ga=2.244504517.1711980662.1654351552-
1941896533.1653805620
21
Shiny R Package

https://gallery.shinyapps.io/cran-explorer/?_ga=2.244504517.1711980662.1654351552-
1941896533.1653805620 22
Examples

23
Education

24
Education

https://vnijs.shinyapps.io/radiant/?_ga=2.248192583.1711980662.1654351552-
1941896533.1653805620&SSUID=0f416394c2
25
Education

https://radiant-rstats.github.io/docs/
26
Finance / Banking

27
Finance / Banking

28
https://phillyo.shinyapps.io/intelligentsia/_w_7d800edd/#
Government / Public Sector

29
Government / Public Sector

30
Government / Public Sector

31
Life Sciences

32
Life Sciences

33
https://haozhu233.shinyapps.io/shinyMRI-contest/?_ga=2.252894025.1711980662.1654351552-1941896533.1653805620
Sports

34
Sports

35
Sports

36
https://allezcannes.shinyapps.io/Soccer_squads/?_ga=2.12705399.1711980662.1654351552-1941896533.1653805620
Technology

37
Technology

38
https://johncoene.shinyapps.io/chirp_demo/?_ga=2.20527608.1711980662.1654351552-1941896533.1653805620
Technology

39
https://johncoene.shinyapps.io/chirp_demo/?_ga=2.20527608.1711980662.1654351552-1941896533.1653805620
Miscellaneous

40
Miscellaneous

41
https://gadenbuie.shinyapps.io/tweet-conf-dash/?_ga=2.209835989.1711980662.1654351552-1941896533.1653805620
Miscellaneous

42
https://gadenbuie.shinyapps.io/tweet-conf-dash/?_ga=2.209835989.1711980662.1654351552-1941896533.1653805620
First R Codes

43
First R Codes

library(shiny)
ui <- fluidPage(
"Hello, world!"
)
server <- function(input, output, session) {
}
shinyApp(ui, server)

44
First R Codes

• This is a complete, if trivial, Shiny app! Looking closely at the code above, our app.R
does four things:

1. It calls library(shiny) to load the shiny package.

2. It defines the user interface, the HTML webpage that humans interact with. In this case,
it’s a page containing the words “Hello, world!”.

3. It specifies the behaviour of our app by defining a server function. It’s currently empty,
so our app doesn’t do anything, but we’ll be back to revisit this shortly.

4. It executes shinyApp(ui, server) to construct and start a Shiny application from UI and
server.

45
First R Codes
library(shiny)
ui <- fluidPage(
selectInput("dataset",
label = "Dataset",
choices = ls("package:datasets")),
verbatimTextOutput("summary"),
tableOutput("table")
)
server <- function(input, output, session) {
output$summary <- renderPrint({
dataset <- get(input$dataset, "package:datasets")
summary(dataset)
})

output$table <- renderTable({


dataset <- get(input$dataset, "package:datasets")
dataset
})
}
shinyApp(ui, server) 46
First R Codes

47
First R Codes

library(shiny)
animals <- c("dog", "cat", "mouse", "bird", "other", "I hate animals")

ui <- fluidPage(
### Free text
textInput("name", "What's your name?"),
passwordInput("password", "What's your password?"),
textAreaInput("story", "Tell me about yourself", rows = 3),

### Numeric inputs


numericInput("num", "Number one", value = 0, min = 0, max = 100),
sliderInput("num2", "Number two", value = 50, min = 0, max = 100),
sliderInput("rng", "Range", value = c(10, 20), min = 0, max = 100),

### Dates
dateInput("dob", "When were you born?"),
dateRangeInput("holiday", "When do you want to go on vacation next?"),

### Limited choices


selectInput("state", "What's your favourite state?", state.name),
radioButtons("animal", "What's your favourite animal?", animals),

radioButtons("rb", "Choose one:",


choiceNames = list(
icon("angry"),

),
icon("smile"),
icon("sad-tear") Inputs
choiceValues = list("angry", "happy", "sad")
),

selectInput(
"state", "What's your favourite state?", state.name,
multiple = TRUE
),

checkboxGroupInput("animal", "What animals do you like?", animals),

checkboxInput("cleanup", "Clean up?", value = TRUE),


checkboxInput("shutdown", "Shutdown?"),

### File uploads

fileInput("upload", NULL),

### Action buttons


actionButton("click", "Click me!"),
actionButton("drink", "Drink me!", icon = icon("cocktail")),

fluidRow(
actionButton("click", "Click me!", class = "btn-danger"),
actionButton("drink", "Drink me!", class = "btn-lg btn-success")
),
fluidRow(
actionButton("eat", "Eat me!", class = "btn-block")
)

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

}
shinyApp(ui, server)

48
First R Codes

Inputs

49
First R Codes

Outputs

library(shiny)

ui <- fluidPage(
textOutput("text"),
verbatimTextOutput("code")
)
server <- function(input, output, session) {
output$text <- renderText("Hello friend!")
output$code <- renderPrint(summary(1:10))
}

shinyApp(ui, server)

50
First R Codes

Outputs

51
First R Codes

Outputs

library(shiny)

ui <- fluidPage(
textOutput("text"),
verbatimTextOutput("print")
)
server <- function(input, output, session) {
output$text <- renderText("hello!")
output$print <- renderPrint("hello!")
}
shinyApp(ui, server)

52
First R Codes

Outputs

53
First R Codes

Outputs

library(shiny)

ui <- fluidPage(
textOutput("text"),
verbatimTextOutput("print")
)
server <- function(input, output, session) {
output$text <- renderText("hello!")
output$print <- renderPrint("hello!")
}
shinyApp(ui, server)

54
First R Codes

Outputs

55
First R Codes

Outputs

library(shiny)

ui <- fluidPage(
tableOutput("static"),
dataTableOutput("dynamic")
)
server <- function(input, output, session) {
output$static <- renderTable(head(mtcars))
output$dynamic <- renderDataTable(mtcars, options =
list(pageLength = 5))
}

shinyApp(ui, server)

56
First R Codes

Outputs
57
First R Codes

Outputs

library(shiny)

ui <- fluidPage(
plotOutput("plot", width = "400px")
)
server <- function(input, output, session) {
output$plot <- renderPlot(plot(1:5), res = 96)
}

shinyApp(ui, server)

58
First R Codes

Outputs
59
First R Codes

Reactivity

ui <- fluidPage(
textInput("name", "What's your name?"),
textOutput("greeting")
)

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


output$greeting <- renderText({
paste0("Hello ", input$name, "!")
})
}

60
First R Codes

Reactivity
61
First R Codes

Reactivity
ui <- fluidPage(
fluidRow(
column(4,
"Distribution 1",
numericInput("n1", label = "n", value = 1000, min = 1),
numericInput("mean1", label = "µ", value = 0, step = 0.1),
numericInput("sd1", label = "σ", value = 0.5, min = 0.1, step = 0.1)
),
column(4,
"Distribution 2",
numericInput("n2", label = "n", value = 1000, min = 1),
numericInput("mean2", label = "µ", value = 0, step = 0.1),
numericInput("sd2", label = "σ", value = 0.5, min = 0.1, step = 0.1)
),
column(4,
"Frequency polygon",
numericInput("binwidth", label = "Bin width", value = 0.1, step = 0.1),
sliderInput("range", label = "range", value = c(-3, 3), min = -5, max = 5)
)
),
fluidRow(
column(9, plotOutput("hist")),
column(3, verbatimTextOutput("ttest"))
)
)

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


output$hist <- renderPlot({
x1 <- rnorm(input$n1, input$mean1, input$sd1)
x2 <- rnorm(input$n2, input$mean2, input$sd2)

freqpoly(x1, x2, binwidth = input$binwidth, xlim = input$range)


}, res = 96)

output$ttest <- renderText({


x1 <- rnorm(input$n1, input$mean1, input$sd1)
x2 <- rnorm(input$n2, input$mean2, input$sd2)

t_test(x1, x2)
})
}

shinyApp(ui, server)

62
First R Codes

Reactivity

63
First R Codes

Reactivity
64
First R Codes

Reactivity
library(shiny)

ui <- fluidPage(
fluidRow(
column(3,
numericInput("lambda1", label = "lambda1", value = 3),
numericInput("lambda2", label = "lambda2", value = 5),
numericInput("n", label = "n", value = 1e4, min = 0)
),
column(9, plotOutput("hist"))
)
)
server <- function(input, output, session) {
x1 <- reactive(rpois(input$n, input$lambda1))
x2 <- reactive(rpois(input$n, input$lambda2))
output$hist <- renderPlot({
freqpoly(x1(), x2(), binwidth = 1, xlim = c(0, 40))
}, res = 96)
}
shinyApp(ui, server)

65
First R Codes

Reactivity
66
First R Codes

Reactivity
library(shiny)

ui <- fluidPage(
shinyFeedback::useShinyFeedback(),
numericInput("n", "n", value = 10),
textOutput("half")
)

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


half <- reactive({
even <- input$n %% 2 == 0
shinyFeedback::feedbackWarning("n", !even, "Please select an even
number")
input$n / 2
})

output$half <- renderText(half())


}

shinyApp(ui, server)

67
First R Codes

Reactivity
68
First R Codes

Reactivity
library(shiny)

ui <- fluidPage(
selectInput("language", "Language", choices = c("", "English",
"Maori")),
textInput("name", "Name"),
textOutput("greeting")
)

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


greetings <- c(
English = "Hello",
Maori = "Kia ora"
)
output$greeting <- renderText({
paste0(greetings[[input$language]], " ", input$name, "!")
})
}
shinyApp(ui, server)

69
First R Codes

Reactivity
70
First R Codes

Reactivity
library(shiny)

ui <- fluidPage(
sidebarLayout(
sidebarPanel(
numericInput("n", "Number of colours", value = 5, min = 1),
uiOutput("col"),
),
mainPanel(
plotOutput("plot")
)
)
)

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


col_names <- reactive(paste0("col", seq_len(input$n)))

output$col <- renderUI({


map(col_names(), ~ textInput(.x, NULL, value = isolate(input[[.x]])))
})

output$plot <- renderPlot({


cols <- map_chr(col_names(), ~ input[[.x]] %||% "")
# convert empty inputs to transparent
cols[cols == ""] <- NA

barplot(
rep(1, length(cols)),
col = cols,
space = 0,
axes = FALSE
)
}, res = 96)
}

shinyApp(ui, server)

71
First R Codes

Reactivity
72
First R Codes

Lissajous curve
library(shiny)

ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("omega", "omega", value = 1, min = -2, max = 2, step = 0.01),
sliderInput("delta", "delta", value = 1, min = 0, max = 2, step = 0.01),
sliderInput("damping", "damping", value = 1, min = 0.9, max = 1, step = 0.001),
numericInput("length", "length", value = 100)
),
mainPanel(
plotOutput("fig")
)
)
)
server <- function(input, output, session) {
t <- reactive(seq(0, input$length, length.out = input$length * 100))
x <- reactive(sin(input$omega * t() + input$delta) * input$damping ^ t())
y <- reactive(sin(t()) * input$damping ^ t())

output$fig <- renderPlot({


plot(x(), y(), axes = FALSE, xlab = "", ylab = "", type = "l", lwd = 2)
}, res = 96)
}

shinyApp(ui, server)

73
First R Codes

Lissajous curve
74
First R Codes

library(shiny)
runExample("01_hello")

75
First R Codes

library(shiny)
runExample("02_text")

76
First R Codes

library(shiny)
runExample("03_reactivity")

77
Shiny Cheat Sheet

78
Shiny Cheat Sheet

79
Shiny Cheat Sheet

80
Shiny Cheat Sheet

81
Shiny Cheat Sheet

82
Shiny Cheat Sheet

83
Shiny Cheat Sheet

84
Shiny Cheat Sheet

85
Shiny Cheat Sheet

86
Free Online Books

87
Free Online Books

https://mastering-shiny.org/index.html

88
Free Online Books

Best Practices (For Advanced Users)

•In Chapter 17, I’ll briefly introduce you to the big ideas of software engineering.

•In Chapter 18, I’ll show you how to extract code out of your Shiny app in to independent
apps, and discuss why you might want to do so.

•In Chapter 19, you’ll learn about Shiny’s module system, which allows you to extract
coupled UI and server code into isolated and reusable components.

•In Chapter 20, I’ll show you how to turn your app in R package, and motivate why that
investment will pay off for bigger apps.

•In Chapter 21, you’ll learn how to turn your existing informal tests into automated test that
can easily be re-run whenever your app changes.

•In Chapter 23, you’ll learn how to identify and resolve performance bottlenecks in your
apps, ensuring they remain speedy even when used by hundreds of users.

89
Free Online Books

Free Course with Four Interactive Modules

https://rstudio-education.github.io/shiny-course/

90
Shiny Commercials

91
Shiny Commercials

92
R/Bioconductor Shiny Packages

93
R Shiny Packages

94
R-Bioconductor Shiny Packages

95
https://www.bioconductor.org/
R Shiny Packages in
Bioinformatics Journal

96
https://academic.oup.com/bioinformatics
R Markdown

97
R Markdown

98
R Markdown

99
R Markdown

100
R Markdown

101
R Markdown

102
R Markdown

103
R Markdown

104
R Markdown

105
R Markdown Chet Sheet

106
R Markdown Cheat Sheet

107
R Markdown Cheat Sheet

108
R Markdown Cheat Sheet

109
R Markdown Cheat Sheet

110
R Markdown Cheat Sheet

111
R Markdown Cheat Sheet

112
R Markdown Cheat Sheet

113
R Markdown Cheat Sheet

114
R Markdown Cheat Sheet

115
R Markdown Cheat Sheet

116
R Markdown Books

https://bookdown.org/yihui/rmarkdown/ https://bookdown.org/yihui/rmarkdown-cookbook/

117
Shinny Process

https://shiny.rstudio.com/articles/
118
Case Studies:
Functional Data Analysis

119
https://academic.oup.com/bioinformatics
Case Studies:
COVID-19 in the World and Spain

Manuel Febrero Bande


University of Santiago de Compostela

120
https://academic.oup.com/bioinformatics
COVID-19 in the World and Spain

Manuel Febrero Bande


University of Santiago de Compostela
121
Address: http://modestya.usc.es:3838/covid19prediction/
Case Studies:
Statfda

Manuel Escabias Machuca


And
Ana María Aguilera del Pino

University of Granada

122
https://academic.oup.com/bioinformatics
Statfda

123
http://www.statfda.com/
Statfda

124
Statfda

125
Statfda

126
Statfda

127
Statfda

128
Statfda

129
Statfda

130
Statfda

131
Statfda

132
Statfda

133
Statfda

134
Statfda

135
Statfda

136
Statfda

137
Statfda

138
Case Studies:
refund.shiny
Julia Wrobel
University of Colorado Denver

And

Jeff Goldsmith
Columbia University

139
https://academic.oup.com/bioinformatics
refund.shiny

140
refund.shiny
Functional Principal Component Analysis with Shiny and refund

## Not run:
library(refund)
library(dplyr)

##### FPCA Example on real data #####

data(cd4)
SC = fpca.sc(cd4)
plot_shiny(SC)

141
refund.shiny
Functional Principal Component Analysis with Shiny and refund

142
refund.shiny
Functional Principal Component Analysis with Shiny and refund

143
refund.shiny
Functional Principal Component Analysis with Shiny and refund

144
refund.shiny
Functional Principal Component Analysis with Shiny and refund

145
refund.shiny
Functional Principal Component Analysis with Shiny and refund

146
refund.shiny
Functional Principal Component Analysis with Shiny and refund

data(DTI)
DTI = DTI[complete.cases(DTI),]
fit.fosr = bayes_fosr(cca ~ pasat + sex, data = DTI)
plot_shiny(fit.fosr)

147
refund.shiny
Function-on-Scalar Regression with Shiny and refund

148
refund.shiny
Function-on-Scalar Regression with Shiny and refund

149
refund.shiny
Function-on-Scalar Regression with Shiny and refund

150
refund.shiny
Function-on-Scalar Regression with Shiny and refund

151
refund.shiny
Function-on-Scalar Regression with Shiny and refund

152
refund.shiny
Function-on-Scalar Regression with Shiny and refund

153
refund.shiny
Function-on-Scalar Regression with Shiny and refund

154
refund.shiny
Function-on-Scalar Regression with Shiny and refund

155
refund.shiny
Function-on-Scalar Regression with Shiny and refund

156
refund.shiny
Function-on-Scalar Regression with Shiny and refund

157
refund.shiny
Function-on-Scalar Regression with Shiny and refund

158
End

Thank you your attention !

159
View publication stats

You might also like