我有一个数据框,我想在一个闪亮的应用程序中显示。我使用一些selectInput
函数来对我的数据进行子集化。我还想使用函数conditionalPanel
来仅显示部分数据。取决于所选的cannel。不幸的是,我使用的方法没有显示任何表格。有没有人有建议?
希望所有括号都在正确的位置,因为我为公众改变了我的代码。
数据:
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))
UI:
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_channel",
label = "channel",
choices = c("online",
"ooh",
"event"))),
mainPanel("My table",
textOutput("output_milieu"),
textOutput("output_product"),
conditionalPanel(condition = "select_cannel == 'online'",
tableOutput("gapminder_table_online")),
conditionalPanel(condition = "select_cannel == 'ooh'",
tableOutput("gapminder_table_ooh")),
conditionalPanel(condition = "select_cannel == 'event'",
tableOutput("gapminder_table_event"))
)
)
))
服务器:
shinyServer(function(input, output) {
output$gapminder_table_online <- renderTable({
subset(data_test[,2:4],
milieu == input$select_milieu & product == input$select_product)
})
output$gapminder_table_event <- renderTable({
subset(data_test[,c(2,3,5)],
milieu == input$select_milieu & product == input$select_product)
})
output$gapminder_table_ooh <- renderTable({
subset(data_test[,c(2,3,6)],
milieu == input$select_milieu & product == input$select_product)
})
output$output_milieu <- renderText({
paste("milieu", input$select_milieu)
})
output$output_product <- renderText({
paste("product", input$select_product)
})
output$output_cannel <- renderText({
paste("cannel", input$select_cannel)
})
})
答案 0 :(得分:0)
您的条件有拼写错误('select_channel'中缺少'h'),也没有完整指定输入变量。如下所示更新它们,然后它应该按照需要工作:
...
conditionalPanel(condition = "input.select_channel == 'online'",
tableOutput("gapminder_table_online")),
conditionalPanel(condition = "input.select_channel == 'ooh'",
tableOutput("gapminder_table_ooh")),
conditionalPanel(condition = "input.select_channel == 'event'",
tableOutput("gapminder_table_event"))
...
我觉得我应该注意,看起来你的代码肯定存在其他问题。