-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim_app.R
78 lines (42 loc) · 1.67 KB
/
sim_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
library(shiny)
library(dplyr)
# Define UI for app -----------------------------------------------------------
ui <- fluidPage(
theme = bslib::bs_theme(bootswatch = "darkly"),
# Sidebar layout with input and output definitions ----------------------------
sidebarLayout(
# Sidebar panel for inputs ----------------------------------------------------
sidebarPanel(
#Set shape with Slider
sliderInput(inputId = "trials",
label = "Select the number of trials to run",
min = 500,
max = 1000,
value = 500),
),
#Main Panel Output: Show scatter plots and data table -------------------------
mainPanel(
tableOutput(outputId = "datatable"),
textOutput(sidebarPanel, outputId = "text"),
)
)
)
#Define server -------------------------------------------------------------
server <- function(input, output, session) {
output$datatable <- renderTable({
{revenue = runif(input$trials,155000, 182500)
fixed_cost = runif(input$trials,52000,57000)
variable_cost = runif(input$trials,100000,105000)
#total = min revenue, fixed_cost, variable
results <- data.frame(revenue, fixed_cost, variable_cost)
}
})
output$text <- renderText({
#results$profit <- with(results, revenue - fixed_cost - variable_cost)
results$profit <- with(results, revenue - fixed_cost - variable_cost)
x <- sum(results$profit < 0) / input$trials *100
paste("Risk Loss Score Percent: ", x)
})
}
#Create a shiny appp object -------------------------------------------------
shinyApp(ui = ui, server = server)