-
Notifications
You must be signed in to change notification settings - Fork 2
/
stapp.R
55 lines (51 loc) · 1.58 KB
/
stapp.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
#' simple app to show different ways of examining variation over body sites and MSAs
#' @import shiny
#' @importFrom dplyr filter
#' @importFrom plotly ggplotly plotlyOutput renderPlotly
#' @rawNamespace import(ggplot2, except=last_plot)
#' @export
variation_app = function() {
cwd = getwd()
on.exit(setwd(cwd))
setwd(system.file("stapp", package="YESCDS"))
shiny::runApp()
}
variation_app_old = function() {
data("woncan", package="YESCDS")
sites = unique(woncan$`Cancer Sites`)
ss = strsplit(woncan$msa, ", ")
woncan$state = sapply(ss, "[", 2)
ui = fluidPage(
sidebarLayout(
sidebarPanel(width=2,
helpText("WONDER CDC Cancer rates"),
selectInput("casite", "body site", choices=sort(sites),
selected="Brain", multiple=TRUE)),
mainPanel(
tabsetPanel(
tabPanel("bystate",
plotlyOutput("boxes")
),
tabPanel("histogram",
plotlyOutput("hist")
)
)
)
)
)
server = function(input, output) {
output$boxes = renderPlotly({
dat = woncan |> filter(`Cancer Sites` %in% input$casite)
#boxplot(split(dat$Age.Adjusted.Rate, dat$state))
g = ggplot(dat, aes(y=Age.Adjusted.Rate, x=state)) + geom_boxplot(aes(group=state)) + theme(axis.text.x = element_text(angle = 90))
ggplotly(g, tooltip="text")
})
output$hist = renderPlotly({
dat = woncan |> filter(`Cancer Sites` %in% input$casite)
#boxplot(split(dat$Age.Adjusted.Rate, dat$state))
g = ggplot(dat, aes(x=Age.Adjusted.Rate, text=msa)) + geom_histogram(aes(text=msa))
ggplotly(g)
})
}
runApp(list(ui=ui, server=server))
}