-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using the new color option in version 1.0.0 #42
Comments
@tanerumit thanks for the question. I have struggled with the color argument for the life of this widget. We have a couple of options. Note, Ideally, if I had supported doesn't work right now
So, the only option we have is to apply the color in sort of works
Looks like I have some work to do. Hopefully, this will be ok for now and sorry for the trouble. |
Thanks @timelyportfolio! That works well for the moment. Looking forward for the revised version! |
@timelyportfolio based on your solution, here is a related problem. The below code takes diamonds data.frame and assigns blue or red color to parcoords data based on the selected variable (input$color.var) and a threshold value (input$pthreshold). This works fine, but if we use crosstalk to for dynamically linking to a datatable, it fails. Any ideas? library(parcoords)
library(dplyr)
library(tidyr)
library(DT)
library(crosstalk)
#### UI-SIDE -------------------------------------------------------------------
ui <- fluidPage(
column(3,
inputPanel(
uiOutput('color.varUI'),
uiOutput('pthresholdUI')
)
),
column(9,
parcoordsOutput("pc"),
dataTableOutput("mytable1")
)
)
#### SERVER-SIDE ---------------------------------------------------------------
server <- function(input, output, session) {
data <- ggplot2::diamonds %>% slice(1:1000) %>% select(carat, depth, table, price)
output$color.varUI = renderUI({
selectizeInput(
inputId = "color.var",
label = "Variable",
choices = colnames(data), #colnames(parcoordsData()),
selected = colnames(data)[1], #colnames(parcoordsData())[1],
multiple = FALSE
)
})
parcoordsDf <- reactive({
req(input$color.var)
req(input$pthreshold)
data$bin_color <- ifelse(data %>% pull(input$color.var) > input$pthreshold, 1, 0)
data
})
sharedDf <- SharedData$new(parcoordsDf)
output$mytable1 <- DT::renderDataTable({
req(parcoordsDf())
sharedDf$data(withSelection = TRUE) %>%
filter(selected_ | is.na(selected_)) %>%
mutate(selected_ = NULL) %>%
datatable()
})
output$pthresholdUI = renderUI({
req(input$color.var)
sliderInput(inputId = "pthreshold",
label = "Threshold",
ticks = FALSE,
step = NULL, #this needs to be fixed
min = data %>% pull(input$color.var) %>% min() %>% round(),
max = data %>% pull(input$color.var) %>% max() %>% round(),
value = data %>% pull(input$color.var) %>% mean() %>% round(),
round = 0,
)
})
output$pc <- renderParcoords({
parcoords(
data = sharedDf,
rownames = FALSE,
color = list(
colorBy = "bin_color",
colorScheme = c("blue", "red")
),
tasks = list(htmlwidgets::JS("
function() {
HTMLWidgets.parcoordsWidget.methods.hide.call(this.parcoords, ['names','bin_color'])
}
")),
brushMode = "1d",
brushPredicate = "and",
alphaOnBrushed = 0.3,
reorderable = TRUE,
axisDots = TRUE,
bundleDimension = NULL,
bundlingStrength = 0,
withD3 = TRUE,
width = NULL,
height = 500
)
})
}
shinyApp(ui = ui, server = server)
|
Actually, I think the problem is the new color argument doesn't work well with crosstalk (SharedData objects). |
Hi,
I see that the new color option is easier to use:
parcoords(
mtcars
, color = list(
colorBy = "cyl"
, colorScale = "scaleOrdinal"
, colorScheme = "schemeCategory10"
)
, withD3 = TRUE
)
However, it is somewhat less flexible. As in the example below, how can I define custom bins and assign custom colors to each bin?
diamonds[sample(1:nrow(diamonds),1000),] %>%
select( carat, color, cut, clarity, depth, table, price, x, y, z) %>%
parcoords(
rownames = F # turn off rownames from the data.frame
, brushMode = "2D-strums"
, reorderable = T
, queue = T
, color = list(
colorBy = "carat"
,colorScale = htmlwidgets::JS(sprintf('
d3.scale.threshold()
.domain(%s)
.range(%s)
'
,jsonlite::toJSON(seq(0,round(max(diamonds$carat))))
,jsonlite::toJSON(RColorBrewer::brewer.pal(6,"PuBuGn"))
))
)
)
The text was updated successfully, but these errors were encountered: