ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
787 stars 208 forks source link

Unhelpful error when using the `renderFoo` function incorrectly #216

Open daattali opened 8 years ago

daattali commented 8 years ago

Suppose I make a widget called foo and have a renderFoo() function. The correct way to use it in shiny is to call eg. renderFoo(foo(data)). But if it's a very simple widget that doesn't have many options and I just want to pass in data, I can easily forget that I'm supposed to call foo() and instead try to call

renderFoo(data)

When I do that, I get an error with a different unhelpful message depending on what the data is ("$ operator is invalid for atomic vectors" if it's a string, "object of type 'closure' is not subsettable" if it's a dataframe)

I suspect this error stems from this innocent line: https://github.com/ramnathv/htmlwidgets/blob/master/R/htmlwidgets.R#L405

It's certainly not a bug in htmlwidgets, but I think it'd be better for the user , especially for beginners, to have a more informative error/check

ramnathv commented 8 years ago

Good point @daattali. I think we can make renderFoo check whether the first argument being passed on to it is of the correct class, and if not, return an informative error message.