-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp_v2.R
144 lines (123 loc) · 4.09 KB
/
app_v2.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(Cairo)
options(shiny.usecairo=T)
source("app_functions.R")
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Am I number or am I color?"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("n",
"Number of samples:",
min = 50,
max = 800,
value = 150),
actionButton("upN", "Change sample size"),
sliderInput("bins",
"Complexity:",
min = 1,
max = 26,
value = 1),
h3("da model"),
verbatimTextOutput("modx")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
#verbatimTextOutput("outout"),
plotOutput("fixPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
myData = dataGen(n=150)
observeEvent(input$upN, {
myData = dataGen(n=trunc(input$n))
# temp <- values$df_data
# temp = c(temp, shiPro(3,input$name,input$descr))
#ds$val[[nrow(ds$val)+1]] <- shiPro(3,input$name,input$descr)
# ds$val = rbind(ds$val,data.frame("id"=nrow(ds$val)+1, "name"=input$name, "descr"=input$descr))
# write.table(ds$val, "14.txt",row.names = F)
})
#nSlider = reactive({dataGen(n=trunc(input$n))})
parList = c("x1", "x2", "x3", "I(x1^2)","I(x1^3)",
"x4","x1*x2","I(x2^2)","I(x2^3)",
"x1*x3","I(x3^2)","I(x3^3)",
"x2*x3")
parList = c(parList,paste0("I(x1^",4:16,")")
)
newmula = "y~1"
xModels = c(newmula)
for (i in 1:26){
newmula = paste(newmula, parList[i],sep=" + ")
xModels = c(xModels,newmula)
}
# #poly only
# parList = paste0("I(x1^",2:16,")")
# newmula = "y~1+x1"
# xModels = c(newmula)
# for (i in 1:15){
# newmula = paste(newmula, parList[i],sep=" + ")
# xModels = c(xModels,newmula)
# }
output$modx <- renderPrint({xModels[input$bins]})
output$distPlot <- renderPlot({
input$upN
myn <- isolate(input$n)
# # generate bins based on input$bins from ui.R
# x <- faithful[, 2]
# bins <- seq(min(x), max(x), length.out = input$bins + 1)
#
# # draw the histogram with the specified number of bins
# hist(x, breaks = bins, col = 'darkgray', border = 'white')
jaVal(as.formula(xModels[input$bins]), myData,folds = 5,repetitions = 10,plot=T)
})
########################
# All together
########################
# vRMSEtrain = c()
# vRMSEtest = c()
# vR2train = c()
# vR2test = c()
# for(i in 1:length(xModels)){
# temp = jaVal(as.formula(xModels[i]), dataGen(n=trunc(150)),folds = 5,repetitions = 10,plot=F)
# vRMSEtrain = c(vRMSEtrain, temp$trainRmse)
# vRMSEtest = c(vRMSEtest, temp$testRmse)
# vR2train = c(vR2train, temp$trainR2)
# vR2test = c(vR2test, temp$testR2)
# }
# myYlim = c(
# min(min(vRMSEtrain,na.rm=T),min(vRMSEtest,na.rm=T)),
# max(max(vRMSEtrain,na.rm=T),max(vRMSEtest,na.rm=T))
# )
# myYlim = c(0,1)
# print(myYlim)
# output$fixPlot = renderPlot({
# plot(0, type="n",xlim=c(0,length(xModels)), ylim=myYlim)
# lines(vR2train,col="red")
# lines(vR2test,col="blue")
# })
output$fixPlot = renderPlot({
# multiGen(input$n,150,xModels)
input$upN
myn <- isolate(input$n)
multiGen(100,myn,xModels[1:18])
})
output$outout <- renderPrint({
#print(vRMSEtest)
#jaVal(as.formula(xModels[input$bins]), dataGen(n=trunc(input$n)),folds = 5,repetitions = 10,plot=F)$trainR
})
}
# Run the application
shinyApp(ui = ui, server = server)