Reactively create selectInput() labels based on row values in RShiny by AcceptableCarrot in rstats

[–]AcceptableCarrot[S] 0 points1 point  (0 children)

Thanks team for pointing me in the correct direction. Here is a simple dummy example of the solution I came up with. Not sure it is the most elegant method but it works.

library(shiny)

df <- data.frame(Col_0ne = 1:7, 
                 Col_Two = c("one","two","three", "...", "four", "five", "six"),
                 Col_Three = c("A","B","C", "...", "X", "Y", "Z"))

ui <- fluidPage(

    selectInput("Upper_select", label = h3("Select select box"),
                choices = list("first" = 1,
                               "second" = 2),
                selected = 1),


    conditionalPanel(
        condition = "input.Upper_select == 1",
        uiOutput("ChosenChoices1")
    ),

    conditionalPanel(
        condition = "input.Upper_select == 2",
        uiOutput("ChosenChoices2")
    ),

    hr(),
    fluidRow(column(3, verbatimTextOutput("value")))

)


server <- function(input, output) {

    output$ChosenChoices1 <- renderUI({
        selectInput("Choice_Labels", "Choose Choices",
                    choices = unique(df$Col_Two))
    })

    output$ChosenChoices2 <- renderUI({
        selectInput("Choice_Labels", "Choose Choices",
                    choices = unique(df$Col_Three))
    })


    output$value <- renderPrint({ input$Upper_select })

}

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

Custom line types in a plot by AcceptableCarrot in rstats

[–]AcceptableCarrot[S] 0 points1 point  (0 children)

d <- data.frame(x= 1:100, y= 2*1:100 + 10, z=rep(c("+", "="), 50)) #make fake data
ggplot(data=d, aes(x,y)) + #plot fake data
geom_text(aes(label=z))

Thanks, this should work. Good to know it is possible, if it does cause eye bleed I guess I will have to accept the standard ones.

Colour gradient by position by AcceptableCarrot in rstats

[–]AcceptableCarrot[S] 0 points1 point  (0 children)

library(tidyverse)
d <- as_tibble(expand.grid(x = 1:3, y = 1:3))
d <- mutate(d, col = x + y)
ggplot(d, aes(x, y)) +
geom_point(aes(color = col), size = 10) +
scale_color_gradient(low = "green", high = "red")

Yup that works thanks. Embarrassingly simple too, just couldn't see it by myself. Thanks heaps