我的数据框如下:
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
,我创建了一个闪亮的应用程序,其中每个x
值都有4个滑块,并带有一个显示result
频率的直方图。我想做的是根据darkblue
值的组合用不同于result
的颜色突出显示x
的值。例如,如果我选择4,6,11,15
(df
的第一行),那么101
栏应突出显示。如果我从前4行的每一行中选择一个值,则101,108,103,107
应该用与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")
)
}