-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve the add_straight_line module #85
Comments
@npaszty opinion from the email conversation
|
@npaszty library(shiny)
library(ggplot2)
library(teal.devel)
ui_add_lines <- function(id) {
ns <- NS(id)
div(
panel_group(id = ns("panel")),
actionButton(ns("add_line"), "add line")
)
}
srv_add_lines <- function(id) {
moduleServer(id, function(input, output, session) {
queue <- teal:::ReactiveQueue$new()
observeEvent(input$add_line, {
new_name <- tail(make.unique(c("line", names(queue$get()), "line"), sep = "-"), 1)
queue$push(
setNames(list(srv_add_line(id = new_name)), new_name)
)
})
queue
})
}
srv_add_line <- function(id) {
moduleServer(id, function(input, output, session) {
values <- reactiveVal()
insertUI(
selector = "#lines-panel",
ui = panel_item(
id = session$ns("line"),
title = id,
radioButtons(session$ns("orientation"), "Line orientation", choices = c("horizontal", "vertical", "column")),
numericInput(session$ns("value"), "Line value", value = 5),
textInput(session$ns("label"), "Label", value = "Horizontal line"),
shinyWidgets::colorPickr(session$ns("color"), label = "Color")
)
)
orientation <- eventReactive(input$orientation, input$orientation)
value <- eventReactive(input$value, input$value)
label <- eventReactive(input$label, input$label)
color <- eventReactive(input$color, input$color)
list(orientation = orientation, value = value, label = label, color = color)
})
}
ui <- bootstrapPage(
column(width = 4, ui_add_lines("lines")),
column(8, plotOutput("plot"))
)
server <- function(input, output, session) {
plot <- reactive(
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()
)
queue <- srv_add_lines(id = "lines")
line_params <- reactive({
sapply(
queue$get(),
function(x) {
line <- sapply(
x,
function(xx) xx(),
simplify = FALSE
)
if (line$orientation == "horizontal") {
geom_hline(yintercept = line$value, color = line$color)
} else {
geom_vline(xintercept = line$value, color = line$color)
}
}
)
})
output$plot <- renderPlot(plot() + line_params())
}
shinyApp(ui, server)
How would you like these values to be drawn? Currently in teal.goshawk, arbitrary straight lines don't depend on anything, one can set the line which bases on the variable, but this value is constant in for all data points (no grouping by gender or anything). Please see the app how single line input can look like. Imagine that this set of inputs can be added and removed using (+) and (x) buttons. We also need some solution to minimalize space which these input takes |
@gogonzo like the idea of improving the UI and use of real estate. when discussing with stakeholder they were fine with the three fields. still if you have slicker way to do this then all in on that. maybe a demo for me since I'm struggling with the images. |
Moving to backlog - need more precise design and user input |
Currently the module for arbitrary lines takes to much space and is not user friendly.
My proposition is to reduce the space of the module and to have it more robust. Requirements of the implementation:
proposition 1 - popup window
To add the new line user clicks (+) button which triggers small window to pop, with inputs for value, color and label. After submitting small bullet describing the line stays in the encoding panel and new straight line is drawn on the plot. One can also remove (+) and modify (~) the line by clicking relevant buttons.
proposition 2 - collapsible div
To add the new line user clicks (+) which adds collapsible-div with inputs for value, color and label. In contrast to the option-1 these inputs does not disappear but they can be hidden by folding the div to the minimal size. Modifying the lines would require just unfolding div and clicking the inputs as usual. User can remove single line inputs by clicking (x)
Design file
https://app.diagrams.net/#G12KVOtFwNMMgFsrjpRAgLtHpOr5wSd4JN
The text was updated successfully, but these errors were encountered: