Last active
April 10, 2016 17:03
-
-
Save gghatano/9770287 to your computer and use it in GitHub Desktop.
Shiny test
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(shiny) | |
library(ggplot2) | |
library(kernlab) | |
library(dplyr) | |
library(magrittr) | |
shinyServer(function(input, output){ | |
output$distPlot = reactivePlot(function(){ | |
param = 10 ^ input$param | |
#package 'kernlab' = kernel pca | |
data(iris) | |
iris_data = iris[, 1:4] | |
iris_lab = iris[, 5] | |
#kernel pca | |
#kernel = gaussian, sigma=0.0003 | |
#feature dim =2 | |
result = kpca(~., data=iris_data, features=2, kpar=list(sigma=param)) | |
df = rotated(result) | |
df_lab = df %>% | |
as.data.table %>% | |
cbind(iris_lab) %>% | |
setnames(c("x", "y","species")) | |
title = paste( "kernel PCA", "(parameter sigma = ", param, ")") | |
gp = ggplot(df_lab, aes(x=x, y=y, shape=species, col = species)) + | |
geom_point(size=4) + ggtitle(title) + | |
theme(plot.title = element_text(size = 20, face = "bold")) | |
print(gp) | |
}) | |
}) |
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(shiny) | |
shinyUI( | |
pageWithSidebar( | |
headerPanel("PCA (Gaussian kernel)"), | |
sidebarPanel( | |
sliderInput("param", | |
"parameter: log_10 (sigma)", | |
min = -4, | |
max = 4, | |
step = 0.5, | |
value = 0, | |
animate = animationOptions(interval=1250, loop=T)) | |
), | |
mainPanel( | |
plotOutput("distPlot") | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment