Skip to content

Commit

Permalink
Merge pull request #1 from joshgabriel/python-R-bokeh
Browse files Browse the repository at this point in the history
Python r bokeh
  • Loading branch information
joshgabriel authored Oct 14, 2016
2 parents 26623e1 + 7c492fb commit b2d984c
Show file tree
Hide file tree
Showing 1,532 changed files with 47,918 additions and 154,174 deletions.
21 changes: 21 additions & 0 deletions benchmark-view/Big_Picture_To_Do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
What we want to do in this branch:
"create a flask app independent of bokeh server that runs on Apache and can render an Iframe from Shiny R"
- which uses bokeh's crossfilter model classes (that makes use of pandas dataframe tools)
to crossfilter data
- the flask app server will interact directly with the REST api of benchmark-db
- use python for
- use Shiny R to create html that can be Iframed into python served flask app for the data analysis.
- this flask app can be wrapped around with an Apache or Nginx server.

User interface goals
- User sees at /home.html a website that looks like https://materialsweb.org/nist_page
- the webpage itself can have a periodic table type interactive interface or a library website like
form with drop down lists or text entry elements
- for now the UI can directly be the crossfilter UI of click and drag
- data crossfiltered into the UI, if it can be statistically analyzed can be launched separately
- by if statistically analyzed means if the data is within dimensions accessible by the statistical tools
For example: 2D data can be fit using regression tools
** provide a link to examples of data crossfiltered correctly so that it can be analyzed with the
statistics.
- an about page linked that summarizes the project
- a contact page linked that summarizes whom to contact
48 changes: 48 additions & 0 deletions benchmark-view/ShinyApps/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "ERROR",
"evalue": "Error in parse(text = x, srcfile = src): <text>:1:1: unexpected input\n1: %run regression.r\n ^\n",
"output_type": "error",
"traceback": "Error in parse(text = x, srcfile = src): <text>:1:1: unexpected input\n1: %run regression.r\n ^\nTraceback:\n"
}
],
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.3.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
45 changes: 45 additions & 0 deletions benchmark-view/ShinyApps/helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Note: percent map is designed to work with the counties data set
# It may not work correctly with other data sets if their row order does
# not exactly match the order in which the maps package plots counties
plot_k_el_2D <- function(k_data, element) {

plot(k_data, element)


}

percent_map <- function(var, color, legend.title, min = 0, max = 100) {

# generate vector of fill colors for map
shades <- colorRampPalette(c("white", color))(100)

# constrain gradient to percents that occur between min and max
var <- pmax(var, min)
var <- pmin(var, max)
percents <- as.integer(cut(var, 100,
include.lowest = TRUE, ordered = TRUE))
fills <- shades[percents]

# plot choropleth map
map("county", fill = TRUE, col = fills,
resolution = 0, lty = 0, projection = "polyconic",
myborder = 0, mar = c(0,0,0,0))

# overlay state borders
map("state", col = "white", fill = FALSE, add = TRUE,
lty = 1, lwd = 1, projection = "polyconic",
myborder = 0, mar = c(0,0,0,0))

# add a legend
inc <- (max - min) / 4
legend.text <- c(paste0(min, " % or less"),
paste0(min + inc, " %"),
paste0(min + 2 * inc, " %"),
paste0(min + 3 * inc, " %"),
paste0(max, " % or more"))

legend("bottomleft",
legend = legend.text,
fill = shades[c(1, 25, 50, 75, 100)],
title = legend.title)
}
85 changes: 85 additions & 0 deletions benchmark-view/ShinyApps/regression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
library(shiny)
library(rbokeh)
library(htmlwidgets)
source("helpers.R")
records <- read.csv("Rdata.csv")
app <- shinyApp(ui = fluidPage(
titlePanel("Least Squares Regression"),

sidebarLayout(
sidebarPanel("input dashboard",
h5("Select the element to plot:"),

sliderInput("points", "Number of points:",
min=1, max=35, value= c(0,35), step=1.0 ),

selectInput("element",
label="Element: ",
choices= c("Al",
"W",
"Ni" ),
selected = "Al"),

selectInput("regression",
label="Regression Model: ",
list("y~x",
"y~exp(-x)") )

),
mainPanel("output plot and table",
img(src='MGI_Logo.png', height = 100, width = 100),
textOutput("text1"),
textOutput("text2"),
rbokehOutput("plotb"),
tableOutput("rlm")
)
)
),
server = function(input,output){

output$text1 <- renderText({
paste("You have selected", input$element)
})

output$text2 <- renderText({
paste("You have selected first", input$points[1]-1, "points and last", length(records$Kpoint) - input$points[2] + 1, "points","total", input$points[1] -1 + length(records$Kpoint) - input$points[2], "out of", length(records$Kpoint))
})

datk <- reactive({
st <- input$points[1]
mid <- input$points[2]
end <- length(records$Kpoint)
append(records$Kpoint[1:st], records$Kpoint[mid:end])
})

datp <- reactive({
st <- input$points[1]
mid <- input$points[2]
end <- length(records$Kpoint)
switch(input$element,
"Al" = append(records$Al[1:st], records$Al[mid:end]),
"W" = append(records$W[1:st], records$W[mid:end]),
"Ni" = append(records$Ni[1:st], records$Ni[mid:end]) )
})


output$plotb <- renderRbokeh({
## define the figure dimensions to be square, plot scatter function
figure(plot_width=200, plot_height=200, xlab="kpoints", ylab="Lattice constant") %>% ly_points( datk(), datp() )
})

output$rlm <- renderTable({
data_fit <- data.frame(x=datk(), y=datp())
lmR <- switch(input$regression,
"y~x" = lm("y~x", data_fit),
"y~exp(-x)" = lm("y~exp(-x)", data_fit) )
lmResult <- summary(lmR)
con <- confint(lmR, level=0.96)
cbind(lmResult$coefficients, con)
})


}
)
runApp(app)

1 change: 1 addition & 0 deletions benchmark-view/benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import loader
Loading

0 comments on commit b2d984c

Please sign in to comment.