r - How to set scale_x_log10(FALSE/TRUE) by checkbox in shiny? -
the following code not work. have change?
specific: want x-axis change logaritmic scale when checkbox ticked.
ui <- shinyui(fluidpage( ... checkboxinput("logarithmicx", "show x-axis in log10", false), checkboxinput("logarithmicy", "show y-axis in log10", false), ... ))
server <- shinyserver(function(input, output) { output$distplot <- renderplot({ ... xlog <- reactive({ switch(input$logarithmicx, true == true, false == false) }) ylog <- reactive({ switch(input$logarithmicy, true == true, false == false) }) ggplot(datasetinput(), aes(size)) + geom_histogram(bins = biins) + theme_bw() + scale_x_log10("logarithmicx") +scale_y_log10("logarithmicy") })
something this:
output$distplot <- renderplot({ mygg <- ggplot(datasetinput(), aes(size)) + geom_histogram(bins = biins) + theme_bw() if(input$logarithmicx) mygg <- mygg + scale_x_log10() if(input$logarithmicy) mygg <- mygg + scale_y_log10() return(mygg) })
edit: working example.
library(shiny) library(ggplot2) runapp( shinyapp( ui = { pagewithsidebar( headerpanel('http://stackoverflow.com/questions/38327254'), sidebarpanel( checkboxinput("logarithmicx", "show x-axis in log10", false), checkboxinput("logarithmicy", "show y-axis in log10", false) ), mainpanel( plotoutput('distplot') ) ) }, server = function(input, output) { output$distplot <- renderplot({ mygg <- ggplot(mtcars, aes(mpg)) + geom_histogram() if(input$logarithmicx) mygg <- mygg + scale_x_log10() if(input$logarithmicy) mygg <- mygg + scale_y_log10() return(mygg) }) } ) )
Comments
Post a Comment