-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
90 lines (73 loc) · 2.57 KB
/
server.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
library(shiny)
library(DT)
library(RColorBrewer)
plot_cols <- brewer.pal(11, 'Spectral')
# Based on this (https://rdrr.io/github/rstudio/rsconnect/src/tests/testthat/test-bundle.R)
# I originally thought this option needs to be FALSE but not sure now
#options(rsconnect.python.enabled = F)
#getOption('rsconnect.python.enabled')
shinyServer(function(input, output) {
if (!Sys.info()[['sysname']] == 'Darwin'){
reticulate::virtualenv_create(envname = 'python35_env', python= '/usr/bin/python3')
reticulate::virtualenv_install('python35_env', packages = c('numpy'))
}
reticulate::use_virtualenv('python35_env', required = TRUE)
reticulate::source_python('python_functions.py')
# Generate the requested distribution
d <- reactive({
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
return(dist(input$n))
})
# Generate a plot of the data
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
return(hist(d(),
main = paste0('Distribution plot: ', dist, '(n = ', n, ')'),
col = plot_cols))
})
# Testing that the Python functions have been imported
output$message <- renderText({
return(test_string_function(input$str))
})
# Testing that numpy function can be used
output$xy <- renderText({
z = test_numpy_function(input$x, input$y)
return(paste0('x + y = ', z))
})
# Display info about the system running the code
output$sysinfo <- DT::renderDataTable({
s = Sys.info()
df = data.frame(Info_Field = names(s),
Current_System_Setting = as.character(s))
})
# Display system path to python
output$python_version <- renderText({
paste0('which python: ', Sys.which('python'))
})
# Display whether rsconnect opt was enabled
output$rsconnect_opt <- renderText({
paste0('rsconnect.python.enabled: ', getOption('rsconnect.python.enabled'))
})
# Display whether a path to virtualenv was provided
output$virtualenv_defined <- renderText({
paste0('Virtualenv defined by user? ', DEFINE_VIRTUALENV)
})
# Display RETICULATE_PYTHON
output$ret_env_var <- renderText({
paste0('echo $RETICULATE_PYTHON: ', Sys.getenv('RETICULATE_PYTHON'))
})
# Display RETICULATE_PYTHON_ENV?
output$ret_env <- renderText({
paste0('echo $RETICULATE_PYTHON_ENV: ', Sys.getenv('RETICULATE_PYTHON_ENV'))
})
# Display PATH
output$path <- renderText({
paste0('PATH: ', Sys.getenv('PATH'))
})
})