-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.R
83 lines (55 loc) · 2.08 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
library(shiny)
library(tidyverse)
# proportion pixel size data set
dat <- readr::read_csv('pixel_size.csv', show_col_types = FALSE)
# function that outputs pixel dimensions for relative risk/risk ratios and proportions
pixel_size_output <- function(type, number){
if(type == "Relative Risk"){
# range for relative risk is assumed 0-6 at the moment
rr_pixel <- number * (95/5) + 5 - 19
return(tibble(`Pixel Dimension` = paste0(as.character(sprintf("%01.2f", rr_pixel))," x ",
as.character(sprintf("%01.2f", rr_pixel)))))
}
else if(type == "Proportion (Normal)"){
if(number > 1){
stop("Please enter proportions in decimal format")
}
pos_int <- round(number,2)
pos_val <- dat %>%
filter(Positive == pos_int) %>%
mutate(Value = paste0(sprintf("%01.2f", Value)," x ", sprintf("%01.2f", Value))) %>%
select(`Pixel Dimension` = Value)
return(pos_val)
}
else{
if(number > 1){
stop("Please enter proportions in decimal format")
}
neg_int <- round(number,2)
neg_val <- dat %>%
filter(Negative == neg_int) %>%
mutate(Value = paste0(sprintf("%01.2f", Value)," x ", sprintf("%01.2f", Value))) %>%
select(`Pixel Dimension` = Value)
return(neg_val)
}
}
ui <- fluidPage(
titlePanel("Pixel Size for Proportions and Relative Risk"),
# create radio button options and numeric input
ui <- fluidPage(
radioButtons("metric", "Is the Pixel Size for a Proportion or Relative Risk?",
c("Proportion (Normal)", "Proportion (Opposite)", "Relative Risk"), inline = T),
numericInput("num", "Value", value = 0)
),
# output in console text format
mainPanel(
verbatimTextOutput("code")
)
)
server <- function(input, output) {
output$code <- renderPrint({
# print the pixel dimension based on radio button option and inputted value
pixel_size_output(input$metric, input$num)
})
}
shinyApp(ui = ui, server = server)