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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -