Monday, 15 March 2010

r - RMarkdown V2 Shiny Document and dplyr -



r - RMarkdown V2 Shiny Document and dplyr -

i'm trying utilize input selection rmarkdown v2 dplyr select columns reported. selected column used in formula given nls() function determine value of constant c.

my code follows:

--- title: "test" author: "author" date: "wednesday, june 18, 2014" output: html_document runtime: shiny --- ```{r, echo=true} require(dplyr) #some sample random info in data.frame: test=data.frame(a=runif(n=10),v=runif(n=10),n=runif(n=10)) #input box take desired column inputpanel( selectinput('sample.choice', label = 'choose columns', choices = c('v sample'='v', 'n sample'='n'), selected='n') ) #make reactive data.frame used nls function test2=reactive(test%.%select(a,input$sample.choice)) #display data.frame renderdatatable(test2()) #use nls solver determine constant given formula: c.fit=reactive(nls(a ~ i(c*input$sample.choice),data=test2(),start=list(c=1))) rendertext(summary(c.fit())) ```

i output error: non-numeric argument mathematical function after phone call renderdatatable , rendertext.

can help me figure out wrong here?

update

based on @wch comments, have fixed dplyr select function. trying phone call rendertext, output of summary.nls of type list. won't work, , needed run renderprint instead. see below working code:

```{r, echo=true} require(dplyr) test=data.frame(a=runif(n=10),v=runif(n=10),n=runif(n=10)) inputpanel( selectinput('sample.choice', label = 'choose columns', choices = c('v sample'='v', 'n sample'='n'), selected='n') ) rendertext(input$sample.choice) test2=reactive(test%.%select(a,matches(input$sample.choice))) renderdatatable(test2()) renderprint({ data=test2() formula=paste0('a ~ i(c*',input$sample.choice,')') c.fit=nls(formula,data=data,start=list(c=1)) summary(c.fit) }) ```

i think problem line:

test %>% select(a, input$sample.choice)

ends resolving this:

test %>% select(a, "v")

but dplyr needs because uses non-standard evaluation:

test %>% select(a, v)

this possible workaround:

test %>% select(a, matches(input$sample.choice))

r shiny dplyr rmarkdown

No comments:

Post a Comment