R 在反应表中显示百分位(闪亮)
我希望显示具有低-高百分比的表格,以识别极端数据。 我的最终目标是在我的DB(闪亮)中显示不同tabPanel中的每个选项卡((带有百分位80的tab1)。 我试了很多东西,但都不管用 为了解释,我给出了一个最少的代码:R 在反应表中显示百分位(闪亮),r,reactive,dt,R,Reactive,Dt,我希望显示具有低-高百分比的表格,以识别极端数据。 我的最终目标是在我的DB(闪亮)中显示不同tabPanel中的每个选项卡((带有百分位80的tab1)。 我试了很多东西,但都不管用 为了解释,我给出了一个最少的代码: 按过滤器和周期显示数据的箱线图 显示方框图中显示的所有数据的主选项卡 显示20%的选项卡(不工作) 你有什么建议来解决这个问题并可能简化编程吗 非常感谢你的贡献 #data data<- data.frame(stringsAsFactors=FALSE,
#data
data<- data.frame(stringsAsFactors=FALSE,
id=c("1", "2", "3", "4", "5", "6", "7","8","9"),
um = c("A1234","A1234","C1345","C1345","Z4453","C1345","C1345","Z4453","A1234"),
time= c(1, 12 , 11, 34, 47, 3, 5, 8, 12),
week =c("2020-002","2020-011","2020-011","2020-005","2020-004","2020-005","2020-011","2020-005","2020-006"),
month =c("2020-01","2020-03","2020-03","2020-02","2020-01","2020-02","2020-03","2020-02","2020-02"),
year1 = c("2020","2020","2020","2020","2020","2020","2020","2020","2020"))
library(shiny)
library(dplyr)
library(ggplot2)
library(plotly)
library(DT)
ui<- shinyUI( fluidRow(
column(2,
selectInput(inputId = "dur_um",
label = "UM",
choices = as.character(unique(data$um)),
multiple=TRUE,
width = validateCssUnit(200))),
column(2, selectInput("period",
label="Display by:",
choices = c("Week_"= "week",
"Month_" = "month",
"Year_" = "year1"),
selected = "month",
width = validateCssUnit(100))),
plotOutput("graph1", width = "400px", height = "200px"), br(),
DT::dataTableOutput("tab"), br(),
DT::dataTableOutput("tab_h")) )
server <- function(input, session, output) {
periode<- reactive({
if (input$period == "week") { "week"
} else if (input$period == "month") { "month"
} else { "year1" }
})
datatime <- reactive({
dur_um <- if (is.null(input$dur_um)) unique(data$um) else input$dur_um
data %>%
filter( um %in% dur_um) %>%
group_by_(periode())
})
# global graph
output$graph1 <- renderPlot({
ggplot(datatime(), aes(.data[[periode()]], y =time )) +
geom_boxplot(aes(fill = stage(.data[[periode()]], after_scale = alpha(fill, 0.4))))
})
# Global tab (without filter on percentile)
output$tab <- DT::renderDataTable({
datatable(datatime(),
options = list(
pageLength = 50,
filter = 'top',
class = "hover"))
})
#data to filt on 20 percentile
data_h <- reactive({
dur_um <- if (is.null(input$dur_um)) unique(data$um) else input$dur_um
data %>%
filter( um %in% dur_um) %>%
group_by_(periode()) %>%
summarise(p20 = quantile(time, probs = c(0.20), na.rm = FALSE, type=2),
.groups = "drop") })
#tab with filt on perc
output$tab_h <- DT::renderDataTable({
datatable(data_h(),
options = list(
pageLength = 50,
filter = 'top',
class = "hover")) })
}
shinyApp(ui,server)
#数据
data在我看来,您的代码中有一个输入错误。您有唯一的(data.duree$um)
这是一块:
#data to filt on 20 percentile
data_h <- reactive({
dur_um <- if (is.null(input$dur_um)) unique(data$um) else input$dur_um
data %>%
filter( um %in% dur_um) %>%
group_by_(periode()) %>%
summarise(p20 = quantile(time, probs = c(0.20), na.rm = FALSE, type=2),
.groups = "drop") })
#要在20%上过滤的数据
数据%
分组依据(周期())%>%
总结(p20=分位数(时间,概率=c(0.20),na.rm=假,类型=2),
.groups=“drop”)})
非常好的评论!但是如何获得与上一个选项卡相同的输出格式(全局数据过滤)?我试图删除“groupby”,但没有成功