Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ce064files
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruna Wundervald
ce064files
Commits
9903f83d
Commit
9903f83d
authored
9 years ago
by
Bruna Wundervald
Browse files
Options
Downloads
Patches
Plain Diff
shiny app scripts
parent
ec393a75
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
FinalProject/server.R
+161
-0
161 additions, 0 deletions
FinalProject/server.R
with
161 additions
and
0 deletions
FinalProject/server.R
0 → 100644
+
161
−
0
View file @
9903f83d
library
(
shiny
);
library
(
knitr
);
shinyServer
(
function
(
input
,
output
,
session
){
file
<-
reactive
({
fileUploaded
<-
input
$
file
if
(
is.null
(
fileUploaded
)){
return
(
NULL
)
}
else
{
return
(
fileUploaded
$
datapath
)
}
})
dataset
<-
reactive
({
fileurl
<-
isolate
(
file
())
input
$
run
if
(
is.null
(
fileurl
)){
return
(
NULL
)
}
else
{
data
<-
read.table
(
fileurl
,
header
=
input
$
header
,
sep
=
input
$
separator
,
quote
=
input
$
quotation
,
dec
=
input
$
decimal
)
return
(
data
)
}
})
observe
({
data
<-
dataset
()
if
(
!
is.null
(
data
))
{
updateSelectInput
(
session
,
inputId
=
"yvar"
,
choices
=
names
(
data
),
selected
=
names
(
data
)[
1
])
updateCheckboxGroupInput
(
session
,
inputId
=
"choosenvar"
,
choices
=
names
(
data
))
}
})
output
$
instructions
<-
renderUI
({
l0
<-
""
l1
<-
"This Shiny App executes simple or multiple linear regression
analysis."
l2
<-
"The dataset longley is available to exemplify all that can be
done here."
l3
<-
"But the main idea is that the user itself will upload a .csv
file and run the analysis."
break1
<-
""
l4
<-
"So, starting by the sidebar. First, you may check a box to see
the example running, or you can just run the analysis yourself,
with your own data. This starts when you check the second box in
the sidebar."
l5
<-
"Then, we have the upload box. This is where you will
upload your own file."
l6
<-
"On the following, the response variable and the explanatory
variables in which there is interest have to be choosen."
break2
<-
""
l7
<-
"Now moving to the tabset. This is the first tab. The next one
will show the dataset to be analysed."
l8
<-
"The third tab is composed by a summary of the linear model
that was adjusted inside this app."
l9
<-
"The next tab shows the model's ANOVA table."
l10
<-
"The fifth tab prints out four plots. They are there to check
for departures from homocedasticity and normality of the model."
break3
<-
""
l11
<-
"At the end, you can download a report (pdf, html or docx),
with the analysis you conducted."
HTML
(
paste
(
l0
,
l1
,
l2
,
l3
,
break1
,
l4
,
l5
,
l6
,
break2
,
l7
,
l8
,
l9
,
l10
,
break3
,
l11
,
sep
=
'<br/>'
))
})
#-----------------------------
fc
<-
reactive
({
y
<-
dataset
()[,
input
$
yvar
]
x
<-
model.matrix
(
~
.
,
dataset
()[,
input
$
choosenvar
])
m
<-
lm
(
y
~
x
)
return
(
list
(
m
=
m
,
y
=
y
))
})
ldata
<-
reactive
({
l
<-
get
(
'longley'
)
yl
<-
l
[,
input
$
longleyy
]
xl
<-
model.matrix
(
~
.
,
l
[,
input
$
longleyx
])
ml
<-
lm
(
yl
~
xl
)
return
(
list
(
l
=
l
,
ml
=
ml
))
})
observe
({
if
(
input
$
example
){
output
$
table
<-
renderDataTable
({
longley
})
output
$
model
<-
renderPrint
({
m0
<-
ldata
()
$
ml
cat
(
"-----"
,
capture.output
(
summary
(
m0
)),
sep
=
"\n"
)
})
output
$
anova
<-
renderPrint
({
m0
<-
ldata
()
$
ml
cat
(
"------------------------"
,
capture.output
(
anova
(
m0
)),
sep
=
"\n"
)
})
output
$
plots
<-
renderPlot
({
m0
<-
ldata
()
$
ml
par
(
mfrow
=
c
(
2
,
2
));
plot
(
m0
)
;
layout
(
1
)
},
width
=
600
,
height
=
600
)
}
if
(
input
$
user
){
output
$
table
<-
renderDataTable
({
inFile
<-
input
$
file
if
(
is.null
(
inFile
))
return
(
NULL
)
read.csv
(
inFile
$
datapath
,
header
=
input
$
header
,
sep
=
input
$
separator
,
quote
=
input
$
quotation
)
})
output
$
model
<-
renderPrint
({
sum1
<-
fc
()
$
m
cat
(
"-----"
,
capture.output
(
summary
(
sum1
)),
sep
=
"\n"
)
})
output
$
anova
<-
renderPrint
({
m1
<-
fc
()
$
m
cat
(
"------------------------"
,
capture.output
(
anova
(
m1
)),
sep
=
"\n"
)
})
output
$
plots
<-
renderPlot
({
m1
<-
fc
()
$
m
par
(
mfrow
=
c
(
2
,
2
));
plot
(
m1
);
layout
(
1
)
},
width
=
600
,
height
=
600
)}
output
$
download
<-
downloadHandler
(
filename
=
function
()
{
paste
(
'my-report'
,
sep
=
'.'
,
switch
(
input
$
format
,
PDF
=
'pdf'
,
HTML
=
'html'
,
Word
=
'docx'
))
},
content
=
function
(
file
)
{
src
<-
normalizePath
(
'report.Rmd'
)
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd
<-
setwd
(
tempdir
())
on.exit
(
setwd
(
owd
))
file.copy
(
src
,
'report.Rmd'
)
library
(
rmarkdown
)
out
<-
render
(
'report.Rmd'
,
switch
(
input
$
format
,
PDF
=
pdf_document
(),
HTML
=
html_document
(),
Word
=
word_document
()
))
file.rename
(
out
,
file
)
}
)
})
}
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment