Create an R object containing shiny tags

126 views
Skip to first unread message

Matt

unread,
Feb 16, 2015, 11:40:36 AM2/16/15
to shiny-...@googlegroups.com
Hello,

I'd like to create an object that stores for example one id and two shiny tags.

setClass(Class="CustomClass",
         representation
= representation(
           id
= "character",
           component1
= "shiny.tag",
           component2
= "shiny.tag"          
         
)
)

But I get the following message :
Warning message:
undefined slot classes in definition of "CustomClass": component1(class "shiny.tag"), component2(class "shiny.tag")

I guess it's because we have :
> getClassDef('shiny.tag')
NULL

I tried to put it as a "list" object but it's also not working. 
How can I do it then ?

Thanks

Winston Chang

unread,
Feb 16, 2015, 2:38:57 PM2/16/15
to Matt, shiny-discuss
The reason it doesn't work with setClass is because shiny.tag is an S3 class, but the setClass function is for the S4 class system.

There shouldn't be anything stopping you from putting tag objects in a list. For example:

a <- div("Tag a")
b <- div("Tag b")

list(
  id = "custom_id",
  component1 = a,
  component2 = b
)


-Winston

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/e07f6297-d9f1-458a-a323-3ad1c57e0e8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt

unread,
Feb 17, 2015, 4:14:23 AM2/17/15
to shiny-...@googlegroups.com, matthie...@gmail.com
Hi Winston.

well, I cannot create a new object with shiny tags if I declare some lists in my class.

setClass(Class="CustomClass",
         representation = representation(
           id = "character",
           component1 = "list",
           component2 = "list"           
         )
)

c = new(Class="CustomClass", id = "1", component1 = selectInput("id1","value :",1:5), component2 = selectInput("id2","value :",6:10) )
Error in validObject(.Object) : 
  invalid class “CustomClass” object: 1: invalid object for slot "component1" in class "CustomClass": got class "shiny.tag", should be or extend class "list"
invalid class “CustomClass” object: 2: invalid object for slot "component2" in class "CustomClass": got class "shiny.tag", should be or extend class "list"

Jeffrey Hanson

unread,
Feb 17, 2015, 8:09:25 PM2/17/15
to Matt, shiny-...@googlegroups.com

Hi,

 

Could you the setOldClass function? EG.

setOldClass('shiny.tag')

setClass(

                Class="CustomClass",

                representation = representation(

                                id = "character",

                                component1 = "shiny.tag",

                                component2 = "shiny.tag"          

                )

)

x=new(Class="CustomClass", id = "1", component1 = selectInput("id1","value :",1:5), component2 = selectInput("id2","value :",6:10))

 

Cheers,

 

Jeff

Matt

unread,
Feb 18, 2015, 4:26:00 AM2/18/15
to shiny-...@googlegroups.com, matthie...@gmail.com
Thank you Jeff, it's what I was looking for :)
Reply all
Reply to author
Forward
0 new messages