mages / googleVis

Interface between R and the Google Chart Tools
https://mages.github.io/googleVis/
360 stars 155 forks source link

Group colors in gvisTimeline #51

Open daheelee opened 7 years ago

daheelee commented 7 years ago

Hello,

I am using gvisTimeline in Shiny, and I need to color code the timeline bars according to groups. This is different from the colorByRowLabel option because I am trying to use the same colors for groups of rows, not by each row label. I know we can just use the options for colors, but I am not able to utilize this because the data set I am using to generate the plot is a reactive object. Is there any way we could add a functionality where you can just use a 'colors' column so that each timeline bar uses the corresponding color for the row, or use 'group' colors in the option?

For example, if I wanted to color code by 'Level', in the dataset below, it would be great if I could do something like:

gvisTimeline(data=dat, rowlabel="Class", barlabel="Day", start="Start", end="End", colors = "Level" ) or gvisTimeline(data=dat, rowlabel="Class", barlabel="Day", start="Start", end="End", colors = "Color" )

screen shot 2016-11-09 at 6 44 14 pm

Thanks for your help!

DL

mages commented 7 years ago

I don’t understand, why you can’t use the options argument in the reactive environment.

On 9 Nov 2016, at 23:57, daheelee notifications@github.com wrote:

Hello,

I am using gvisTimeline in Shiny, and I need to color code the timeline bars according to groups. This is different from the colorByRowLabel option because I am trying to use the same colors for groups of rows, not by each row label. I know we can just use the options for colors, but I am not able to utilize this because the data set I am using to generate the plot is a reactive object. Is there any way we could add a functionality where you can just use a 'colors' column so that each timeline bar uses the corresponding color for the row, or use 'group' colors in the option?

For example, if I wanted to color code by 'Level', in the dataset below, it would be great if I could do something like:

gvisTimeline(data=dat, rowlabel="Class", barlabel="Day", start="Start", end="End", colors = "Level" ) or gvisTimeline(data=dat, rowlabel="Class", barlabel="Day", start="Start", end="End", colors = "Color" )

https://cloud.githubusercontent.com/assets/20231857/20159094/8a07da94-a6ac-11e6-95b9-cae44943c54f.png Thanks for your help!

DL

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mages/googleVis/issues/51, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF-1U6EmGnZbALJ6G3SZXbOWSOzkn4Gks5q8l4EgaJpZM4KuH7V.

daheelee commented 7 years ago

My issue is that the list of colors has to remain reactive but options does not take a reactive object.

So the app I am creating uses a data set is created by reading in a google spreadsheet which is updated by users. Now I have the data set in the Shiny app reactive because I need the app to reflect any changes that are made in the spreadsheet, without having to restart the app. This means the list of colors that is used in the gvisTimeline function needs to remain reactive. But it seems like I can't do this.

As an example, let's say the reactive data set I had in the previous post, and I can make a list of colors according to this. colors_timeline gives a string list of colors from a function (colors) according to 'Level' variable (Advanced is red, Intermediate is yellow, Elementary is blue). So with the example dataset, this would give "['red', 'red', 'yellow', 'yellow', 'blue', 'blue']". But note, this list is reactive.

colors_timeline = reactive({ colors(dat()) })

And I can't use the colors_timeline directly in gvisTimeline function as below because options does not take a reactive object.

output$timeline <- renderGvis({ gvisTimeline(data = dat(), rowlabel = "Day", barlabel = "Class", start = "Start", end = "End", options = list(colors = colors_timeline()) <-this is wrong })

So I was asking if it's possible to add a 'colors' argument in the gvisTimeline function so that color coding with reactive data set is possible.

DL