tutorial reactivity example

1,426 views
Skip to first unread message

Giles Heywood

unread,
Sep 24, 2013, 8:27:51 AM9/24/13
to shiny-...@googlegroups.com
Hi

The answer to this will be blindingly obvious to someone, unfortunately not to me...

I am trying to replicate the tutorial example under 'reactivity overview'.  If I have:

#server.r
library(shiny)
fib <- function(n) ifelse(n<3, 1, fib(n-1)+fib(n-2))
shinyServer(function(input, output) {
  # OK, as long as this is called from the reactive world:
  currentFib <- function() {
    fib(as.numeric(input$n))
  }
  output$nth <- renderText({ currentFib })
})
#ui.r
library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("Reactivity"),
  sidebarPanel(
    selectInput("n","n",as.list(1:10))
  ),  
  mainPanel(
    h4("toy"),
    textOutput("nth")
    )
))

Then I get an error: Error in cat(list(...), file, sep, fill, labels, append) :   argument 1 (type 'closure') cannot be handled by 'cat'

If I add brackets () after currentFib, the app works as expected... is this a typo?  Or am I making an elementary error...

Giles

ZJ

unread,
Sep 24, 2013, 8:49:53 AM9/24/13
to shiny-...@googlegroups.com

currentFib is defined as function so adding () to it makes sense. I think the typo is with the tutorial

Winston Chang

unread,
Oct 2, 2013, 12:27:31 PM10/2/13
to shiny-...@googlegroups.com
Yes, you're right, that is an error. Thanks for pointing it out!


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages