-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inv.Returns.Test.R
58 lines (47 loc) · 2.31 KB
/
Inv.Returns.Test.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
rm(list=ls())
ui <- fluidPage(
titlePanel("Return Distribution"),
theme = shinythemes::shinytheme("spacelab"),
sidebarLayout(
sidebarPanel(width = 0),
mainPanel(
###Remove error messages
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
tabsetPanel(
tabPanel('Return Distribution', plotly::plotlyOutput("plot_Return_Distribution"))),
)
)
)
##########################
Shiny app[server] -------------------------------------------------
server <- function(input, output, session){
output$plot_Return_Distribution <- plotly::renderPlotly({
returns_2020 <- c(0.005, 0.024, 0.039, 0.047, 0.028, 0.0084, 0.0236, 0.0357, 0.072, -0.01, 0.019, 0.045, 0.013, 0.0335, 0.038)
annotation <- list(yref = 'paper', xref = "x", y = 0.5, x = mean(na.omit(returns_2020)), text = paste("Mean = ", round(mean(na.omit(returns_2020))*100,1), "%"))
histogram <- plot_ly(x = ~na.omit(returns_2020),
type = "histogram",
histnorm = "probability",
nbinsx = input$bins,
marker = list(color = "orange",
line = list(color = "black",
width = 2))) %>%
add_segments(x = mean(na.omit(returns_2020)),
xend = mean(na.omit(returns_2020)), y = 0.01, yend = 0.47, showlegend = FALSE) %>%
#add_lines(x = na.omit(returns_2020[,3]), y = density(na.omit(returns_2020[,3]))) %>% # add a density estimate with defa
layout(title = "Probability Distribution of Investment Returns",
xaxis = list(title = "Return Buckets", dtick = 0.01,
tick0 = -0.02,
tickmode = "linear", tickformat = "%",
zeroline = FALSE),
yaxis = list(title = "Share of Pension Plans", tickformat = "%",
range = c(0,0.5),dtick = 0.05,
zeroline = FALSE))%>%
layout(annotations= list(annotation))
histogram
})
}
shinyApp(ui = ui, server = server)
#####`