Skip to content

Instantly share code, notes, and snippets.

@dfjenkins3
Last active April 18, 2017 21:08
Show Gist options
  • Save dfjenkins3/124c1c2e91cc86f8f6080692b8729620 to your computer and use it in GitHub Desktop.
Save dfjenkins3/124c1c2e91cc86f8f6080692b8729620 to your computer and use it in GitHub Desktop.
Shiny Widget Example
library(shiny)
hist_widget <- function() {
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(sliderInput("n", "Bins", 5, 100, 20)),
mainPanel(plotOutput("hist"))
)
),
server = function(input, output) {
output$hist <- renderPlot(
hist(faithful[[2]], breaks = input$n,
col = "skyblue", border = "white")
)
}
)
}
hist_widget()
library(shiny)
library(ggplot2)
library(plotly)
test <- readRDS("tsnedf.rds")
tsne_widget <- function(dataset) {
clusterChoice <- colnames(dataset)[3:ncol(dataset)]
dataset$Sample <- rownames(dataset)
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(selectInput("colorClusters", "Color Clusters By", clusterChoice)),
mainPanel(plotlyOutput("clusterPlot"))
)
),
server = function(input, output) {
output$clusterPlot <- renderPlotly({
ggplotly(ggplot(dataset, aes(X1, X2, label=Sample, color=dataset[,input$colorClusters]))+geom_point())
})
}
)
}
tsne_widget(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment