r - Shiny and ggplot - error when using both scale_x_ and scale_y_continuous -


background: odd one. essentially, working on shiny app people can pull csv export off particular website, upload , interactive it. because numbers large (millions) defaults scientific notation, isn't easy on eye, i'm trying use "labels = comma" correct this.

issue: when have both scale_x_cont , scale_y_cont in ggplot function, app crashes. when have x or y in there, runs fine.

now tried write smallest reproducible piece of code could, when made simple 1 using mtcars , same selectinput method, ran fine, no errors both scale_x_cont , scale_y_cont in place...

error

error in eval(substitute(expr), envir, enclos) : geom_point requires following missing aesthetics: x, y error: geom_point requires following missing aesthetics: x, y

minimal csv replicate with

https://raw.githubusercontent.com/nzcoops/datasets/master/dump_test

app

require(shiny) require(dt) require(ggplot2) require(scales) runapp(   list(     ui = fluidpage(       sidebarpanel(fileinput('file1', 'choose csv file',                              accept=c('text/csv',                                        'text/comma-separated-values,text/plain',                                        '.csv')),                    htmloutput("contents2"),                    htmloutput("contents3")       ),       mainpanel(         plotoutput("plot1"),         datatableoutput("contents4")       )     ),      server = function(input, output, session) {        contents1 <- reactive({         infile <- input$file1         if (is.null(infile))           return(null)         dat <<- read.csv(infile$datapath)         dat[,2:5] <<- lapply(dat[,2:5],function(x){as.numeric(gsub(",", "", x))})         names(dat)       })        output$contents2 <- renderui({         if (is.null(input$file1))           return(null)         selectinput('columnsx', 'columns x', contents1()[3:5])       })        output$contents3 <- renderui({         if (is.null(input$file1))           return(null)         selectinput('columnsy', 'columns y', contents1()[3:5])       })        output$contents4 <- renderdatatable({         if (is.null(input$file1))           return(null)         dat       }, options = list(paging = false, searching = false))        output$plot1 <- renderplot({         if (is.null(input$file1))           return(null)         p <- ggplot(dat, aes_string(x=input$columnsx, y=input$columnsy)) +           geom_point() +            scale_x_continuous(labels = comma) #+ scale_y_continuous(labels = comma)         # remove above hash , presence of scale_y_ crash app         print(p)       })     }   )) 

you have funky scoping stuff going on in function. if replace first line of function this:

p <- ggplot(dat, aes_string(x=dat[input$columnsx], y=dat[input$columnsy])) 

it plot out ok.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -