gpt4 book ai didi

r - 在 Shiny 中过滤表格

转载 作者:行者123 更新时间:2023-12-04 12:09:23 25 4
gpt4 key购买 nike

给出了以下数据集(实际上更多的情况):

data_test = data.frame(ID = c ("1","2","3","4","5"),
product = c("A","B","C","A","C"),
milieu = c("good","medium","bad","medium","bad"),
online = c(1,0,1,1,0),
ooh = c(0,1,0,1,1),
event = c(1,1,0,0,0))

现在我想构建一个 Shiny 的应用程序,有人可以选择一个环境让我们说“好”和一个产品“A”,所有在线都有“1”,并且返回具有这些设置的数据表。在示例 ID 1 中。

我尝试了以下

用户界面:
shinyUI(fluidPage(
titlePanel("product milieu"),

sidebarLayout(
sidebarPanel("select",
selectInput("select_milieu",
label = "Milieu",
choices = list("good",
"medium",
"bad")
),
selectInput("select_product",
label = "Product",
choices = list("A",
"B",
"C")
),
selectInput("select_online",
label = "Online",
choices = list(1,
0)
),
selectInput("select_ooh",
label = "ooh",
choices = list(1,
0)
),
selectInput("select_Event",
label = "Event",
choices = list(1,
0)

)
),
mainPanel("My table",
textOutput("output_milieu"),
textOutput("output_product"),
textOutput("output_event"),
textOutput("output_online"),
textOutput("output_ooh"),
tableOutput("gapminder_table")
)
)
))

服务器:
shinyServer(function(input, output) {

output$gapminder_table <- renderTable({
subset(data_test,
milieu == input$select_milieu & product == input$select_product &
online == input$select_online)

})
output$output_milieu <- renderText({
paste("milieu", input$select_milieu)
})
output$output_product <- renderText({
paste("product", input$select_product)
})
output$output_event <- renderText({
paste("Event", input$select_Event)
})
output$output_online <- renderText({
paste("Online", input$select_Online)
})
output$output_ooh <- renderText({
paste("out of Home", input$select_ooh)
})

})

我现在的问题是如何过滤“事件”和“哦”。有人有建议吗?

提前致谢!

最佳答案

如果您开始探索 DT,您可以让这一切变得更简单。 Shiny 的数据表包。有了这个,您只需在相应列上方输入您喜欢的任何过滤条件。

服务器.R

library(shiny)
library(DT)

data_test = data.frame(ID = c ("1","2","3","4","5"),
product = c("A","B","C","A","C"),
milieu = c("good","medium","bad","medium","bad"),
online = c(1,0,1,1,0),
ooh = c(0,1,0,1,1),
event = c(1,1,0,0,0))

shinyServer(function(input, output) {

output$gapminder_table <- renderDataTable({
data_test
},
filter = 'top',
rownames = FALSE)
})

用户界面
library(shiny)
library(DT)

shinyUI(fluidPage(
titlePanel("product milieu"),

sidebarLayout(
sidebarPanel("Place for other criteria"
),
mainPanel("My table",
dataTableOutput("gapminder_table")
)
)
))

关于r - 在 Shiny 中过滤表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com