I have the dataframe below:
x1<-floor(runif(100, 1,5))
x2<-floor(runif(100, 6,10))
x3<-floor(runif(100, 10,14))
x4<-floor(runif(100, 15,19))
result<-floor(runif(100,100,110))
df<-data.frame(x1,x2,x3,x4,result)
x1 x2 x3 x4 result
1 4 6 11 15 101
2 1 6 12 18 108
3 2 6 13 15 103
4 3 7 13 17 107
5 2 8 10 18 108
6 2 9 12 16 105
and I have a created a shiny app with 4 sliders one for every x
value and a histogram which displays the frequency of result
. What I want to do is highlight with a different color than the darkblue
the values of result
based on the combination of the x
values. If for example I select 4,6,11,15
(first line of the df
) then the 101
bar should be highlighted. If I select one value from every line of the first 4 then 101,108,103,107
should be highlighted with the same color which should be different from darkblue
.
#ui.r
library(shiny)
library(shinyWidgets)
library(ggplot2)
pageWithSidebar(
headerPanel("Histogram"),
sidebarPanel(width=2,
h4("Blood-center specific variables"),
sliderTextInput(
inputId = "col", label = "Annual number of collections",
choices = sort(unique(df$x1),decreasing = F), selected = min(df$x1),
grid = TRUE
),
sliderTextInput(
inputId = "rat", label = "Collection: import ratio ",
choices = sort(unique(df$x2),decreasing = F), selected = min(df$x2),
grid = TRUE
),
sliderTextInput(
inputId = "aph", label = "Apheresis: WB ratio",
choices = sort(unique(df$x3),decreasing = F), selected = min(df$x3),
grid = TRUE
),
sliderTextInput(
inputId = "tra", label = "Current trauma distribution %",
choices = sort(unique(df$x4),decreasing = F), selected = min(df$x4),
grid = TRUE
)
),
mainPanel(
fluidRow(
plotOutput("h1")
)
)
)
#server.r
library(shiny)
library(shinyWidgets)
library(ggplot2)
function(input, output) {
output$h1<-renderPlot(
ggplot(df, aes(x=result))+
geom_histogram(color="darkblue", fill="lightblue")
)
}