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

Research on improving numeric range input using plotly #233

Closed
Tracked by #6
donyunardi opened this issue Mar 20, 2023 · 1 comment · Fixed by #289
Closed
Tracked by #6

Research on improving numeric range input using plotly #233

donyunardi opened this issue Mar 20, 2023 · 1 comment · Fixed by #289

Comments

@donyunardi
Copy link
Contributor

donyunardi commented Mar 20, 2023

continuation from #226

Summary:

User would like the ability to drag numeric ranges and manually enter the range input.

Plotly

Plotly is recommended as one of the solution.

Example from @nikolas-burkoff

          > I would have loved @nikolas-burkoff's proposal if the red brackets are draggable

Using plotly this is possible:

The black lines here are draggable (sadly they are draggable vertically as well but I would hope that could be configured?)

image
(code below)

Separately the example here (after "After @ firmo23's edit:") is really nice

library(shiny)
library(plotly)

data <- data.frame(x = runif(1000))

ui <- fluidPage(
  plotlyOutput("plot"),
  verbatimTextOutput("result")
)

server <- function(input, output, session) {
  output$plot <- renderPlotly(
    plot_ly(data, x = ~x,type="histogram") %>%
      layout(shapes = list(
        list(type = "line", x0 = 0.4, x1 = 0.4, 
             y0 = 0, y1 = 1, yref = "paper"),
        list(type = "line", x0 = 0.8, x1 = 0.8, 
             y0 = 0, y1 = 1, yref = "paper"))) |>
      # allow to edit plot by dragging lines
      config(edits = list(shapePosition = TRUE))  
  )
  
  selected_range_rv <- reactiveVal(c(0.4, 0.8))
  
  observeEvent(plotly::event_data("plotly_relayout"), {
    x <- plotly::event_data("plotly_relayout")
    if ("shapes[0].x0" %in% names(x)){
      selected_range_rv(c(x[["shapes[0].x0"]], selected_range_rv()[2]))  
    }
    if ("shapes[1].x0" %in% names(x)){
      selected_range_rv(c(selected_range_rv()[1], x[["shapes[1].x1"]]))  
    }
  })

  output$result <- renderText({
    sprintf("The selected range is from %f to %f", min(selected_range_rv()), max(selected_range_rv()))
  })
    
}

shinyApp(ui, server)

Originally posted by @nikolas-burkoff in #226 (comment)

Example from @chlebowa

I would have loved @nikolas-burkoff's proposal if the red brackets are draggable

Using plotly this is possible:

Oh, I assumed plotly is off the table, but If not - this is excellent, especially the built-in slider shown in the SO example:

library(plotly)

x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)

fig <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines') %>%
  layout(xaxis = list(rangeslider = list()))

fig

Definition of Done:

  • This is a research task to explore plotly for numeric range input in the filter panel
  • Present a rough implementation prototype using the provided example code
@donyunardi donyunardi changed the title Research on improved numeric range input Research on improved numeric range input using plotly Mar 20, 2023
@donyunardi donyunardi changed the title Research on improved numeric range input using plotly Research on improving numeric range input using plotly Mar 20, 2023
@chlebowa chlebowa self-assigned this May 16, 2023
@chlebowa chlebowa linked a pull request May 30, 2023 that will close this issue
chlebowa added a commit that referenced this issue Jun 14, 2023
Closes #234 
Closes #233 

Replaces the range slider in `RangeFilterState` with an interactive
`plotly` graph. Two shapes (lines) are drawn on the plot that can be
dragged and their position is tracked. An observer listens to events
emitted by the plot when shapes are altered (this event is called a
"plotly_relayout") and updates selection. Another observer listens to
the manual input and updates selection. Finally, a third observer
listens to the selection and updates the manual input as well as the
shapes on the plot.

Since the graph is slower to render, a spinner is added to it to
alleviate the negative effect on UX.

Numeric (manual) input is now displayed simultaneously with the graphic
input, not alternatively.

Numeric input receives a debounce.

---------

Signed-off-by: kartikeya kirar <[email protected]>
Signed-off-by: Aleksander Chlebowski <[email protected]>
Co-authored-by: Dawid Kałędkowski <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: kartikeya kirar <[email protected]>
Co-authored-by: kartikeya <[email protected]>
@chlebowa
Copy link
Contributor

closed by #289

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

Successfully merging a pull request may close this issue.

2 participants