Last active
March 19, 2020 18:08
-
-
Save nassimhaddad/3057e9ac687591fa5138 to your computer and use it in GitHub Desktop.
automatic resize of rChart objects in shiny
This file contains hidden or 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
require(rCharts) | |
require(shiny) | |
smpl<-data.frame(gene = c("gene1","gene2","gene3","gene4","gene5", | |
"gene6","gene7","gene8","gene9","gene10"), | |
direction = c("up","down","up","up","up", | |
"up","up","down","down","down"), | |
type = c("norm","norm","tum","tum","norm", | |
"tum","tum","norm","tum","tum"), | |
foldChange = c(1.3, 0.4, 1.3, 3.0, 1.6, | |
2.9, 1.3, 0.5, 0.5, 0.6)) | |
function(input, output, session) { | |
output$myChart <- renderChart({ | |
n <- subset(smpl, type == input$x) | |
p1 <- nPlot(foldChange ~ gene, group = "direction", n, | |
type = 'multiBarChart', | |
width = session$clientData[["output_plot1_width"]]) # here we get the width | |
p1$set(dom = 'myChart') | |
return(p1) | |
}) | |
# optional, to display the values | |
output$text1 <- renderText({ | |
sprintf("width = %s, height = %s", | |
session$clientData[["output_plot1_width"]], | |
session$clientData[["output_plot1_height"]]) | |
}) | |
} |
This file contains hidden or 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) | |
require(rCharts) | |
shinyUI(pageWithSidebar( | |
headerPanel("Sample Bar Plot"), | |
sidebarPanel( | |
selectInput(inputId = "x", | |
label = "Select:", | |
choices = c("norm","tum"), | |
selected = "norm") | |
), | |
mainPanel( | |
# showOutput("myChart", "nvd3"), | |
chartOutput("myChart", "nvd3"), # the chart that needs automatic resize | |
plotOutput("plot1"), # to get its width value (as this widget takes 100% width by default) | |
textOutput("text1"), # optional, to display the values | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment