Skip to content

Instantly share code, notes, and snippets.

@fbreitwieser
Last active April 20, 2016 22:19
Show Gist options
  • Save fbreitwieser/b4403672b6cc8da4f5f5ec1d68ffd496 to your computer and use it in GitHub Desktop.
Save fbreitwieser/b4403672b6cc8da4f5f5ec1d68ffd496 to your computer and use it in GitHub Desktop.
resizing d3heatmap / renderUI / shinydashboard / DT
library(shiny)
library(d3heatmap)
library(shinydashboard)
library(DT)
ui <- dashboardPage(
dashboardHeader(title="resizing d3heatmap"),
dashboardSidebar(
sliderInput("obs", "Number of rows:", min = 10, max = 100, value = 50)
),
dashboardBody(
tabBox(
tabPanel("Data",DT::dataTableOutput("dt")),
tabPanel("Heatmap",uiOutput("hm_o"))
)
)
)
server <- function(input, output) {
dat <- reactive({
matrix(rnorm(input$obs*4),ncol=4)
})
output$dt <- DT::renderDataTable({ DT::datatable(as.data.frame(dat())) })
output$hm_o <- renderUI({
d3heatmap::d3heatmapOutput('hm',width="50%", height=paste0(50+length(input$dt_rows_current)*10,"px"))
})
output$hm <- renderD3heatmap({
d3heatmap(dat()[input$dt_rows_current,], Colv=FALSE,
colors=colorRampPalette(c("blue", "white", "red"))(100))
})
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment