使用多个变量的R中的子集数据
我是新来的使用多个变量的R中的子集数据,r,shiny,R,Shiny,我是新来的R。我正在尝试创建一个应用程序,允许用户基于多个变量子集adata.frame,然后查看结果数据 以下是一个小示例数据集: iter,wave,apples 1,1,600 1,1,500 1,1,400 1,2,300 1,2,200 1,2,100 2,1,1000 2,1,1100 2,1,1200 2,2,1300 2,2,1400 2,2,1500 3,1,1100 3,1,2200 3,1,3300 3,2,4400 3,2,5500 3,2,6600 我希望用户能够指定
R
。我正在尝试创建一个应用程序
,允许用户基于多个变量子集
adata.frame
,然后查看结果数据
以下是一个小示例数据集:
iter,wave,apples
1,1,600
1,1,500
1,1,400
1,2,300
1,2,200
1,2,100
2,1,1000
2,1,1100
2,1,1200
2,2,1300
2,2,1400
2,2,1500
3,1,1100
3,1,2200
3,1,3300
3,2,4400
3,2,5500
3,2,6600
我希望用户能够指定iter
和wave
的值,并查看结果数据
下面是我尝试的闪亮的代码。我意识到我一定犯了几个愚蠢的错误
编辑
这是我修改过的代码。最终结果现在非常接近我想要的。侧栏
仍无法完美显示
library(shiny)
setwd('C:/Users/mark_/Documents/simple_RShiny_files/explore')
apple.data <- read.csv('subset_data_based_on_multiple_variables.csv',
header = TRUE, stringsAsFactors = FALSE)
ui <- fluidPage(
titlePanel("Subsetting Apple Dataset"),
sidebarLayout(
sidebarPanel(
uiOutput("codePanel")
),
mainPanel(
tableOutput("view")
)
),
selectInput("codeInput", inputId ="data1", label = "Choose Iter", choices = unique(apple.data$iter)),
selectInput("codeInput", inputId ="data2", label = "Choose Wave", choices = unique(apple.data$wave))
)
server <- function(input, output) {
output$codePanel <- renderUI({
})
dataset <- reactive({
subset(apple.data, (iter == input$data1 & wave == input$data2))
})
output$view <- renderTable(dataset())
}
shinyApp(ui = ui, server = server)
库(闪亮)
setwd('C:/Users/mark\uu/Documents/simple\u RShiny\u files/explore')
apple.data问题在于两个selectInputs
具有相同的inputId
。这项工作:
library(shiny)
apple.data <- data.frame(
iter = c(1L,1L,1L,1L,1L,1L,2L,2L,2L,2L,2L,
2L,3L,3L,3L,3L,3L,3L),
wave = c(1L,1L,1L,2L,2L,2L,1L,1L,1L,2L,2L,
2L,1L,1L,1L,2L,2L,2L),
apples = c(600L,500L,400L,300L,200L,100L,1000L,
1100L,1200L,1300L,1400L,1500L,1100L,2200L,3300L,4400L,
5500L,6600L)
)
ui <- fluidPage(
titlePanel("Subsetting Apple Dataset"),
sidebarLayout(
sidebarPanel(
selectInput("codeInput1", label = "Choose Iter", choices = unique(apple.data$iter)),
selectInput("codeInput2", label = "Choose Wave", choices = unique(apple.data$wave))
),
mainPanel(
tableOutput("view")
)
)
)
server <- function(input, output) {
dataset <- reactive({
return(subset(apple.data, (iter == input$codeInput1 & wave == input$codeInput2)))
})
output$view <- renderTable(dataset())
}
shinyApp(ui = ui, server = server)
库(闪亮)
苹果。谢谢。能否从侧边栏中删除“div form group input container”消息?请参阅更新的答案。这回答了你的问题吗?谢谢。那看起来太完美了!在给其他人一个提供替代方案的机会后,我几乎肯定会在一两天内接受你的回答。