【发布时间】:2015-08-25 20:15:34
【问题描述】:
给出了以下数据集(实际上更多的情况):
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))
现在我想构建一个闪亮的应用程序,人们可以在其中选择一个环境让我们说“好”和一个产品“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)
})
})
我现在的问题是如何过滤“事件”和“哦”。有人给点建议吗?
提前致谢!
【问题讨论】:
-
为什么不在同一个
renderTable()步骤中进行所有过滤? -
另外,您没有显示您使用
renderTable()步骤制作的表格是否有原因?你的意思是在你的 ui 中有一个tableOutput("gapminder_table")行吗? -
对不起,我在复制/粘贴过程中忘记了这一点...您将如何在 renderTable() 中进行过滤??
-
和你现在做的一样。我会发布一个答案,以便您了解我的意思。
-
附带说明:
?subset旨在用于交互使用。请参阅帮助文件中的警告部分。使用[或例如dplyr 的filter_函数可能会更好。