Skip to content
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

Prevent multiple selectize/dynamic color brushes from being rendered in shiny #1936

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

cpsievert
Copy link
Collaborator

Closes #1584

@felloumi
Copy link

felloumi commented Apr 15, 2021

Hello,

The new update did prevent multilple selectize/dynamic color from being rendered in shiny and it works for me but the select box is not accessible. I have attached an example. I can not type any entry. How to keep the selectize actif?

Thanks
FE

library(shiny)
library(plotly)
library(ggplot2)

mtcars$brand = rownames(mtcars)


# Define UI 
ui <- fluidPage(
    # Application title
    titlePanel("Testing highlight with shiny"),

    # 
    sidebarLayout(
        sidebarPanel(
            selectInput("xid", "xcol", choices=colnames(mtcars), selected = "cyl"),
            selectInput("yid", "ycol", choices=colnames(mtcars), selected = "mpg"),
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotlyOutput("distPlot")
        )
    )
)

# Define server 
server <- function(input, output) {

    output$distPlot <- renderPlotly({
        mtcars2 <- highlight_key(mtcars, ~brand, "Select brand")
        gg <- ggplot(mtcars2, aes_string(x=input$xid, y=input$yid)) + geom_point()
        ## ggplotly(gg)
        highlight(
            suppressWarnings(ggplotly(gg)),
            on = "plotly_click",
            selectize = TRUE,
            dynamic = TRUE,
            persistent = FALSE
        )
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

@cpsievert
Copy link
Collaborator Author

cpsievert commented Apr 15, 2021

Thanks @felloumi! I just pushed a fix for this (e02a704).

@felloumi
Copy link

Thanks @cpsievert , I can now type an entry but there is still a small box (another non actif select)
Screen Shot 2021-04-15 at 5 20 20 PM

sthagen added a commit to sthagen/plotly-plotly.R that referenced this pull request May 13, 2021
Follow up to plotly#1936: hash the selectize id so it can be used as an HTM…
@felloumi
Copy link

felloumi commented Jun 9, 2021

Hi Carson,

The latest committed version works fine for me. However if you subset or filter the original data the highlighted_key did not change/refresh. The list on the select box is still the original one. Here attached a reproducible example.

library(shiny)
library(plotly)
library(ggplot2)

mtcars$brand = rownames(mtcars)
# dim(mtcars) # 32 12

# Define UI for application that draws a histogram
ui <- fluidPage(
     ## tags$head(includeScript("Untitled.js")),
    # Application title
    titlePanel("Testing highlight with shiny"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            selectInput("xid", "xcol", choices=colnames(mtcars), selected = "cyl"),
            selectInput("yid", "ycol", choices=colnames(mtcars), selected = "mpg"),
            checkboxInput("half", "First Half data", FALSE)
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotlyOutput("distPlot")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
    # mydata <- reactive({if (input$half) return(mtcars[1:16, ]) else return (mtcars) })
    
    # mtcars2 <- highlight_key(mydata, ~brand, "Select brand")
    output$distPlot <- renderPlotly({
        if (input$half) mydata = mtcars[1:16, ] else mydata = mtcars
        mtcars2 <- highlight_key(mydata, ~brand, "Select brand")
        gg <- ggplot(mtcars2, aes_string(x=input$xid, y=input$yid)) + geom_point()
         
        highlight(
            suppressWarnings(ggplotly(gg)),
            on = "plotly_click",
            off=NULL,
            color = "red",
            selectize = TRUE,
            dynamic = FALSE,
            persistent = FALSE
        )
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

So how to change the list of brand names to the half as the data change to half? and refresh the list?

Thanks,

FE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiple selectize/dynamic color brushes rendered in shiny
2 participants