rbokeh
rbokeh copied to clipboard
theme error using categorical value in plotting (on maps) in shiny
The following code returns an error. I am basically trying to make use of the automatic conversion of categorical values to colors when plotting over a map within shiny:
library("shiny")
library("maps")
library("rbokeh")
library("htmlwidgets")
data(world.cities)
caps <- subset(world.cities, capital == 1)
perils <- head(caps,12)
perils$size=c(0.01,0.30,0.43,0.12,0.04,0.06,0.07,0.03,0.21,0.04,0.06,0.08)
perils$kind=c("Wind","Wind","Wind","Wind","Wind","Earthquake","Earthquake","Earthquake","Other","Other","Other","Life")
server <- function(input, output, session) {
output$rbokeh <- renderRbokeh({
figure(width = 800, padding_factor = 0) %>%
ly_map("world", col = "gray") %>%
ly_points(long, lat, data = perils, size = size, color = kind,
hover = c(name, country.etc, kind))
})
}
I get the following error:
Error in get_theme_value(map_item$domain, cur_dat, attr) :
attempt to apply non-function
Upon further testing, I narrowed it down to the size and color (mapped) parameters not playing nicely together:
server <- function(input, output, session) {
output$rbokeh <- renderRbokeh({
figure(width = 800, padding_factor = 0) %>%
ly_map("world", col = "gray") %>%
ly_points(long, lat, data = perils, color = kind,
hover = c(name, country.etc, kind))
})
}
Works fine. Bug or feature?
Even further testing shows there is some nasty interaction between color and size:
library("shiny")
library("maps")
library("rbokeh")
library("htmlwidgets")
data(world.cities)
caps <- subset(world.cities, capital == 1)
perils <- head(caps,12)
perils$siz=c(0.01,0.30,0.43,0.12,0.04,0.06,0.07,0.03,0.21,0.04,0.06,0.08)
perils$kind=c("green","green","green","green","green","blue","blue","blue","red","red","red","black")
server <- function(input, output, session) {
output$rbokeh <- renderRbokeh({
figure(width = 800, padding_factor = 0) %>%
ly_map("world", col = "gray") %>%
ly_points(long, lat, data = perils, size=siz, color = kind,
hover = c(name, country.etc, kind))
})
}
Has clear problems with the legend (neither size nor color yield expected results in the legend)
Thanks for the report. Legend work has been ongoing and more is available in the dev branch. Will hopefully stabilize this and merge into master soon. Here's your example using this branch:
devtools::install_github("bokeh/rbokeh@dev")
library("shiny")
library("maps")
library("rbokeh")
library("htmlwidgets")
data(world.cities)
caps <- subset(world.cities, capital == 1)
perils <- head(caps,12)
perils$size=c(0.01,0.30,0.43,0.12,0.04,0.06,0.07,0.03,0.21,0.04,0.06,0.08)
perils$kind=c("Wind","Wind","Wind","Wind","Wind","Earthquake","Earthquake","Earthquake","Other","Other","Other","Life")
figure(width = 800, padding_factor = 0) %>%
ly_map("world", col = "gray") %>%
ly_points(long, lat, data = perils, size = size * 100, color = kind,
hover = c(name, country.etc, kind))