Last active
March 5, 2020 12:18
-
-
Save kozo2/5f8a7737c8a41988509f9ef2f491c295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dash) | |
library(dashCoreComponents) | |
library(dashHtmlComponents) | |
library(plotly) | |
#library(jsonlite) | |
app <- Dash$new() | |
app$layout( | |
htmlDiv( | |
list( | |
htmlDiv(id='my-div', children = "Dash: A web application framework for R."), | |
dccGraph( | |
id='sepal_len2petal_len', | |
figure=plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length) | |
), | |
dccGraph( | |
id='sepal_len2sepal_wid', | |
figure=plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width) | |
), | |
dccGraph( | |
id='petal_len2petal_wid', | |
figure=plot_ly(data = iris, x = ~Petal.Length, y = ~Petal.Width) | |
) | |
) | |
) | |
) | |
app$callback( | |
#output=list(id='my-div', property='children'), | |
output=list(id='sepal_len2sepal_wid', property='figure'), | |
params=list(input(id = 'sepal_len2petal_len', property = 'selectedData')), | |
function(selectedData) { | |
#save(selectedData, file = "selectedData.RData") | |
xs <- unlist(lapply(selectedData$points, function(sdata){ | |
sdata$x | |
})) | |
ys <- unlist(lapply(selectedData$points, function(sdata){ | |
sdata$y | |
})) | |
target <- unlist(lapply(seq_along(xs), function(x){ | |
intersect( | |
which(iris[,1] == xs[x]), | |
which(iris[,3] == ys[x])) | |
})) | |
target <- sort(unique(target)) | |
new_iris = iris[target, ] | |
return(plot_ly(data = new_iris, x = ~Sepal.Length, y = ~Sepal.Width)) | |
#print(selectedData) | |
# return(plot_ly(data = new_iris, x = ~Sepal.Length, y = ~Sepal.Width)) | |
# return(prettify(toJSON(selectedData),indent = 2)) | |
}) | |
# When you run this in the remote server | |
#app$run_server(host="0.0.0.0") | |
# When you run this in the local server | |
print(app$server$port) | |
app$run_server() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment