Skip to content

Instantly share code, notes, and snippets.

@gghatano
Last active April 10, 2016 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gghatano/9770287 to your computer and use it in GitHub Desktop.
Save gghatano/9770287 to your computer and use it in GitHub Desktop.
Shiny test
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)
})
})
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