I'm trying to create interactive visualisation (using R shiny) but I have a problem, I want to create an interactive barplot, where user is able to select (like subset) data from my df, I want to have a plot of quantiles (from 0.75 to 1, by 0.01). So user can select using slider which quantile of data he wants to see. for example - 10000 value in my column is 0.75 percentile, so when user selects 0.75 percentile order on slider, R shiny generates barplot for this column with values from min value to 10000. same for 0.76 etc...
I've tried but i don't know how to set this, i just can do barplot with number of breaks, but don't know how to set max value like in my desired output
CodePudding user response:
Something like this? You can add some selectInput for the column choice.
library(shiny)
library(tidyverse)
ui <- fluidPage(
titlePanel("Iris Quantile"),
sidebarLayout(
sidebarPanel(
sliderInput("quantile",
"Quantile",
min = 0,
max = 1,
value = 0.75,
step = 0.01)
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
filter_iris <- function(column, value){
quantile_value <- quantile(iris %>% pull(all_of(column)), value)
iris %>% filter(.data[[column]] < quantile_value)
}
output$distPlot <- renderPlot({
ggplot(data = filter_iris("Petal.Length", input$quantile), aes(x = Petal.Length))
geom_bar()
})
}
shinyApp(ui = ui, server = server)