您正在构建一个应用程序来选择给定几个滑块输入的数据集。为了获得多个子集我使用for循环,它不起作用。它假设在表格中显示满足滑块给出的条件的所有组合,但是尽管我要求品牌在某个值以下仍然在表中。如果有人可以提供帮助,请代码和请求的文件如下:
UI.R
library(shiny)
attributes <- unique(dataset_with_key[,2])
len <- length(attributes)
shinyUI (pageWithSidebar (
headerPanel("Testing"),
sidebarPanel(
lapply(1:2, function(i){
sliderInput(paste("weight",i,sep="_"),
paste("Select attribute levels :", attributes[i]),
min = 0,
max = 1,
step=0.05,
# round=-2,
value = c(0,1))
}),
selectInput("variable", "Variable:",
unique(dataset_with_key[,1]))
)
, mainPanel(
tabsetPanel(
tabPanel("Restrictions", h3("Analysis"),
tableOutput("values2"),
tableOutput("values")
),
tabPanel("Information",textOutput("text1"))
)
)
))
SERVER.R
library(shiny)
attributes <- unique(dataset_with_key$Attribute)
tempf <- dataset_with_key$key
shinyServer( function(input,output){
final <- reactive(function(){
tempf <- dataset_with_key
for (i in 1:2){
tempcond <- dataset_with_key[round(tempf$Primary_Weights,2) <=
round( eval(parse(text = paste0(paste('input$weight', i, sep='_'),"[2]"))),2)
& round(tempf$Primary_Weights,2) >=
round(eval(parse(text = paste0(paste('input$weight', i, sep='_'),"[1]"))),2)
& tempf$Attribute==attributes[i],]
tempf <- dataset_with_key[dataset_with_key$key %in% tempcond$key,]
}
tempf
})
output$values <- renderTable ({
final()
})
output$text1 <- renderText({
paste("your command output is ",typeof(final),"Number Of Combinations",length(unique(final()$key)))
})
})
以及数据集的示例:
structure(list(combination = structure(c(47L, 47L, 47L, 47L,
47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L,
47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 58L, 58L, 58L,
58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L,
58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L,
58L, 58L, 58L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L,
69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L,
69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L), .Label = c("Comb_1", "Comb_10",
"Comb_100", "Comb_101", "Comb_102", "Comb_103", "Comb_104", "Comb_105",
"Comb_106", "Comb_107", "Comb_108", "Comb_109", "Comb_11", "Comb_110",
"Comb_111", "Comb_112", "Comb_12", "Comb_13", "Comb_14", "Comb_15",
"Comb_16", "Comb_17", "Comb_18", "Comb_19", "Comb_2", "Comb_20",
"Comb_21", "Comb_22", "Comb_23", "Comb_24", "Comb_25", "Comb_26",
"Comb_27", "Comb_28", "Comb_29", "Comb_3", "Comb_30", "Comb_31",
"Comb_32", "Comb_33", "Comb_34", "Comb_35", "Comb_36", "Comb_37",
"Comb_38", "Comb_39", "Comb_4", "Comb_40", "Comb_41", "Comb_42",
"Comb_43", "Comb_44", "Comb_45", "Comb_46", "Comb_47", "Comb_48",
"Comb_49", "Comb_5", "Comb_50", "Comb_51", "Comb_52", "Comb_53",
"Comb_54", "Comb_55", "Comb_56", "Comb_57", "Comb_58", "Comb_59",
"Comb_6", "Comb_60", "Comb_61", "Comb_62", "Comb_63", "Comb_64",
"Comb_65", "Comb_66", "Comb_67", "Comb_68", "Comb_69", "Comb_7",
"Comb_70", "Comb_71", "Comb_72", "Comb_73", "Comb_74", "Comb_75",
"Comb_76", "Comb_77", "Comb_78", "Comb_79", "Comb_8", "Comb_80",
"Comb_81", "Comb_82", "Comb_83", "Comb_84", "Comb_85", "Comb_86",
"Comb_87", "Comb_88", "Comb_89", "Comb_9", "Comb_90", "Comb_91",
"Comb_92", "Comb_93", "Comb_94", "Comb_95", "Comb_96", "Comb_97",
"Comb_98", "Comb_99"), class = "factor"), Attribute = structure(c(5L,
6L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 9L, 10L, 1L, 2L, 3L, 4L, 5L,
6L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 9L, 10L, 1L, 2L, 4L, 5L,
6L, 11L, 12L, 8L, 1L, 2L, 4L, 5L, 6L, 11L, 12L, 8L, 1L, 2L, 4L,
5L, 6L, 11L, 12L, 8L, 1L, 2L, 4L, 5L, 6L, 11L, 12L, 8L, 1L, 2L,
4L, 5L, 6L, 11L, 8L, 10L, 1L, 2L, 4L, 5L, 6L, 11L, 8L, 10L, 1L,
2L, 4L, 5L, 6L, 11L, 8L, 10L, 1L, 2L, 4L, 5L, 6L, 11L, 8L, 10L,
1L, 2L, 4L, 5L, 6L, 12L, 8L, 1L, 2L, 4L), .Label = c("Brand",
"Camera", "Colour", "Connectivity", "Display_Size", "Input_Method",
"mg_brand", "mg_color", "mg_opersystem", "mg_price2", "Operating_System",
"Price_Bucket"), class = "factor"), Primary_Weights = c(0.0165760131,
0, 0, 0.4382099557, 0.0715554519, 0.4354625906, 0, 0.0135417213,
0, 0.0412302804, 0, 0.416657648, 0.0731228557, 0.410532306, 0.0175337476,
0.0132847392, 0.0280221081, 0.0408465955, 0, 0.5417733265, 0.0142395741,
0.3523226007, 0.0126580754, 0.0130543718, 0.0305692407, 0.0353828109,
0, 0.4599561851, 0.1349562691, 0, 0.0273273821, 0.1398679705,
0.037837, 0.0304305572, 0.1696246359, 0.4688031055, 0.1442811929,
0, 0.0237889734, 0.115486818, 0.0423853165, 0.0448927516, 0.1603618421,
0.5177030547, 0.136576526, 0, 0.0194930818, 0.0936183616, 0.0461031421,
0.0510339776, 0.1354718562, 0.5981180958, 0.1120119023, 0, 0.0244608866,
0.073904943, 0.0374447237, 0.0442274822, 0.1098319663, 0.490429186,
0.1686263243, 0, 0.0253375776, 0.1033618908, 0.0449793998, 0.1672656215,
0, 0.5603062011, 0.1229685727, 0, 0.0209758487, 0.0972089602,
0.0524026324, 0.1461377849, 0, 0.6166255117, 0.0392621558, 0,
0.0243300602, 0.1207420923, 0.05097111, 0.1480690699, 0, 0.7103228618,
0.0267168423, 0, 0.0190666225, 0.0903017086, 0.0384278705, 0.1122011799,
0.0029629144, 0.4839247401, 0.1457474446, 0, 0.027824948, 0.1166001084,
0.0354318356, 0.1904709234, 0.5993858379, 0.0823854869, 0), vif = c(6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 7L, 7L, 7L), pvalue = c(0.6, 0.6, 0.6, 0.7, 0.7, 0.7, 0.7,
0.7, 0.7, 0.7, 0.7, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.9,
0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6,
0.6, 0.6, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9,
0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.7, 0.7, 0.7, 0.7, 0.7,
0.7, 0.7, 0.7, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.9, 0.9,
0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6,
0.7, 0.7, 0.7), key = structure(c(209L, 209L, 209L, 214L, 214L,
214L, 214L, 214L, 214L, 214L, 214L, 219L, 219L, 219L, 219L, 219L,
219L, 219L, 219L, 224L, 224L, 224L, 224L, 224L, 224L, 224L, 224L,
253L, 253L, 253L, 253L, 253L, 253L, 253L, 253L, 258L, 258L, 258L,
258L, 258L, 258L, 258L, 258L, 263L, 263L, 263L, 263L, 263L, 263L,
263L, 263L, 268L, 268L, 268L, 268L, 268L, 268L, 268L, 268L, 297L,
297L, 297L, 297L, 297L, 297L, 297L, 297L, 302L, 302L, 302L, 302L,
302L, 302L, 302L, 302L, 307L, 307L, 307L, 307L, 307L, 307L, 307L,
307L, 312L, 312L, 312L, 312L, 312L, 312L, 312L, 312L, 341L, 341L,
341L, 341L, 341L, 341L, 341L, 346L, 346L, 346L), .Label = c("Comb_10060.6",
"Comb_10070.7", "Comb_10080.8", "Comb_10090.9", "Comb_10160.6",
"Comb_10170.7", "Comb_10180.8", "Comb_10190.9", "Comb_10260.6",
"Comb_10270.7", "Comb_10280.8", "Comb_10290.9", "Comb_10360.6",
"Comb_10370.7", "Comb_10380.8", "Comb_10390.9", "Comb_10460.6",
"Comb_10470.7", "Comb_10480.8", "Comb_10490.9", "Comb_10560.6",
"Comb_10570.7", "Comb_10580.8", "Comb_10590.9", "Comb_1060.6",
"Comb_10660.6", "Comb_10670.7", "Comb_10680.8", "Comb_10690.9",
"Comb_1070.7", "Comb_10760.6", "Comb_10770.7", "Comb_10780.8",
"Comb_10790.9", "Comb_1080.8", "Comb_10860.6", "Comb_10870.7",
"Comb_10880.8", "Comb_10890.9", "Comb_1090.9", "Comb_10960.6",
"Comb_10970.7", "Comb_10980.8", "Comb_10990.9", "Comb_11060.6",
"Comb_11070.7", "Comb_11080.8", "Comb_11090.9", "Comb_11160.6",
"Comb_11170.7", "Comb_11180.8", "Comb_11190.9", "Comb_11260.6",
"Comb_11270.7", "Comb_11280.8", "Comb_11290.9", "Comb_1160.6",
"Comb_1170.7", "Comb_1180.8", "Comb_1190.9", "Comb_1260.6", "Comb_1270.7",
"Comb_1280.8", "Comb_1290.9", "Comb_1360.6", "Comb_1370.7", "Comb_1380.8",
"Comb_1390.9", "Comb_1460.6", "Comb_1470.7", "Comb_1480.8", "Comb_1490.9",
"Comb_1560.6", "Comb_1570.7", "Comb_1580.8", "Comb_1590.9", "Comb_160.6",
"Comb_1660.6", "Comb_1670.7", "Comb_1680.8", "Comb_1690.9", "Comb_170.7",
"Comb_1760.6", "Comb_1770.7", "Comb_1780.8", "Comb_1790.9", "Comb_180.8",
"Comb_1860.6", "Comb_1870.7", "Comb_1880.8", "Comb_1890.9", "Comb_190.9",
"Comb_1960.6", "Comb_1970.7", "Comb_1980.8", "Comb_1990.9", "Comb_2060.6",
"Comb_2070.7", "Comb_2080.8", "Comb_2090.9", "Comb_2160.6", "Comb_2170.7",
"Comb_2180.8", "Comb_2190.9", "Comb_2260.6", "Comb_2270.7", "Comb_2280.8",
"Comb_2290.9", "Comb_2360.6", "Comb_2370.7", "Comb_2380.8", "Comb_2390.9",
"Comb_2460.6", "Comb_2470.7", "Comb_2480.8", "Comb_2490.9", "Comb_2560.6",
"Comb_2570.7", "Comb_2580.8", "Comb_2590.9", "Comb_260.6", "Comb_2660.6",
"Comb_2670.7", "Comb_2680.8", "Comb_2690.9", "Comb_270.7", "Comb_2760.6",
"Comb_2770.7", "Comb_2780.8", "Comb_2790.9", "Comb_280.8", "Comb_2860.6",
"Comb_2870.7", "Comb_2880.8", "Comb_2890.9", "Comb_290.9", "Comb_2960.6",
"Comb_2970.7", "Comb_2980.8", "Comb_2990.9", "Comb_3060.6", "Comb_3070.7",
"Comb_3080.8", "Comb_3090.9", "Comb_3160.6", "Comb_3170.7", "Comb_3180.8",
"Comb_3190.9", "Comb_3260.6", "Comb_3270.7", "Comb_3280.8", "Comb_3290.9",
"Comb_3360.6", "Comb_3370.7", "Comb_3380.8", "Comb_3390.9", "Comb_3460.6",
"Comb_3470.7", "Comb_3480.8", "Comb_3490.9", "Comb_3560.6", "Comb_3570.7",
"Comb_3580.8", "Comb_3590.9", "Comb_360.6", "Comb_3660.6", "Comb_3670.7",
"Comb_3680.8", "Comb_3690.9", "Comb_370.7", "Comb_3760.6", "Comb_3770.7",
"Comb_3780.8", "Comb_3790.9", "Comb_380.8", "Comb_3860.6", "Comb_3870.7",
"Comb_3880.8", "Comb_3890.9", "Comb_390.9", "Comb_3960.6", "Comb_3970.7",
"Comb_3980.8", "Comb_3990.9", "Comb_4060.6", "Comb_4070.7", "Comb_4080.8",
"Comb_4090.9", "Comb_4160.6", "Comb_4170.7", "Comb_4180.8", "Comb_4190.9",
"Comb_4260.6", "Comb_4270.7", "Comb_4280.8", "Comb_4290.9", "Comb_4360.6",
"Comb_4370.7", "Comb_4380.8", "Comb_4390.9", "Comb_4460.6", "Comb_4470.7",
"Comb_4480.8", "Comb_4490.9", "Comb_4560.6", "Comb_4570.7", "Comb_4580.8",
"Comb_4590.9", "Comb_460.6", "Comb_4660.6", "Comb_4670.7", "Comb_4680.8",
"Comb_4690.9", "Comb_470.7", "Comb_4760.6", "Comb_4770.7", "Comb_4780.8",
"Comb_4790.9", "Comb_480.8", "Comb_4860.6", "Comb_4870.7", "Comb_4880.8",
"Comb_4890.9", "Comb_490.9", "Comb_4960.6", "Comb_4970.7", "Comb_4980.8",
"Comb_4990.9", "Comb_5060.6", "Comb_5070.7", "Comb_5080.8", "Comb_5090.9",
"Comb_5160.6", "Comb_5170.7", "Comb_5180.8", "Comb_5190.9", "Comb_5260.6",
"Comb_5270.7", "Comb_5280.8", "Comb_5290.9", "Comb_5360.6", "Comb_5370.7",
"Comb_5380.8", "Comb_5390.9", "Comb_5460.6", "Comb_5470.7", "Comb_5480.8",
"Comb_5490.9", "Comb_5560.6", "Comb_5570.7", "Comb_5580.8", "Comb_5590.9",
"Comb_560.6", "Comb_5660.6", "Comb_5670.7", "Comb_5680.8", "Comb_5690.9",
"Comb_570.7", "Comb_5760.6", "Comb_5770.7", "Comb_5780.8", "Comb_5790.9",
"Comb_580.8", "Comb_5860.6", "Comb_5870.7", "Comb_5880.8", "Comb_5890.9",
"Comb_590.9", "Comb_5960.6", "Comb_5970.7", "Comb_5980.8", "Comb_5990.9",
"Comb_6060.6", "Comb_6070.7", "Comb_6080.8", "Comb_6090.9", "Comb_6160.6",
"Comb_6170.7", "Comb_6180.8", "Comb_6190.9", "Comb_6260.6", "Comb_6270.7",
"Comb_6280.8", "Comb_6290.9", "Comb_6360.6", "Comb_6370.7", "Comb_6380.8",
"Comb_6390.9", "Comb_6460.6", "Comb_6470.7", "Comb_6480.8", "Comb_6490.9",
"Comb_6560.6", "Comb_6570.7", "Comb_6580.8", "Comb_6590.9", "Comb_660.6",
"Comb_6660.6", "Comb_6670.7", "Comb_6680.8", "Comb_6690.9", "Comb_670.7",
"Comb_6760.6", "Comb_6770.7", "Comb_6780.8", "Comb_6790.9", "Comb_680.8",
"Comb_6860.6", "Comb_6870.7", "Comb_6880.8", "Comb_6890.9", "Comb_690.9",
"Comb_6960.6", "Comb_6970.7", "Comb_6980.8", "Comb_6990.9", "Comb_7060.6",
"Comb_7070.7", "Comb_7080.8", "Comb_7090.9", "Comb_7160.6", "Comb_7170.7",
"Comb_7180.8", "Comb_7190.9", "Comb_7260.6", "Comb_7270.7", "Comb_7280.8",
"Comb_7290.9", "Comb_7360.6", "Comb_7370.7", "Comb_7380.8", "Comb_7390.9",
"Comb_7460.6", "Comb_7470.7", "Comb_7480.8", "Comb_7490.9", "Comb_7560.6",
"Comb_7570.7", "Comb_7580.8", "Comb_7590.9", "Comb_760.6", "Comb_7660.6",
"Comb_7670.7", "Comb_7680.8", "Comb_7690.9", "Comb_770.7", "Comb_7760.6",
"Comb_7770.7", "Comb_7780.8", "Comb_7790.9", "Comb_780.8", "Comb_7860.6",
"Comb_7870.7", "Comb_7880.8", "Comb_7890.9", "Comb_790.9", "Comb_7960.6",
"Comb_7970.7", "Comb_7980.8", "Comb_7990.9", "Comb_8060.6", "Comb_8070.7",
"Comb_8080.8", "Comb_8090.9", "Comb_8160.6", "Comb_8170.7", "Comb_8180.8",
"Comb_8190.9", "Comb_8260.6", "Comb_8270.7", "Comb_8280.8", "Comb_8290.9",
"Comb_8360.6", "Comb_8370.7", "Comb_8380.8", "Comb_8390.9", "Comb_8460.6",
"Comb_8470.7", "Comb_8480.8", "Comb_8490.9", "Comb_8560.6", "Comb_8570.7",
"Comb_8580.8", "Comb_8590.9", "Comb_860.6", "Comb_8660.6", "Comb_8670.7",
"Comb_8680.8", "Comb_8690.9", "Comb_870.7", "Comb_8760.6", "Comb_8770.7",
"Comb_8780.8", "Comb_8790.9", "Comb_880.8", "Comb_8860.6", "Comb_8870.7",
"Comb_8880.8", "Comb_8890.9", "Comb_890.9", "Comb_8960.6", "Comb_8970.7",
"Comb_8980.8", "Comb_8990.9", "Comb_9060.6", "Comb_9070.7", "Comb_9080.8",
"Comb_9090.9", "Comb_9160.6", "Comb_9170.7", "Comb_9180.8", "Comb_9190.9",
"Comb_9260.6", "Comb_9270.7", "Comb_9280.8", "Comb_9290.9", "Comb_9360.6",
"Comb_9370.7", "Comb_9380.8", "Comb_9390.9", "Comb_9460.6", "Comb_9470.7",
"Comb_9480.8", "Comb_9490.9", "Comb_9560.6", "Comb_9570.7", "Comb_9580.8",
"Comb_9590.9", "Comb_960.6", "Comb_9660.6", "Comb_9670.7", "Comb_9680.8",
"Comb_9690.9", "Comb_970.7", "Comb_9760.6", "Comb_9770.7", "Comb_9780.8",
"Comb_9790.9", "Comb_980.8", "Comb_9860.6", "Comb_9870.7", "Comb_9880.8",
"Comb_9890.9", "Comb_990.9", "Comb_9960.6", "Comb_9970.7", "Comb_9980.8",
"Comb_9990.9"), class = "factor")), .Names = c("combination",
"Attribute", "Primary_Weights", "vif", "pvalue", "key"), row.names = 100:200, class = "data.frame")
非常感谢你!
答案 0 :(得分:0)
首先,使用eval
通常不是一个好主意。你试图用
eval(parse(text = paste0(paste('input$weight', i, sep='_'),"[2]")))
可以用
完成text = input[[paste0("weight", i, sep='_')]][2]
代替。但我认为你真正的问题是在循环中,你没有做任何事情来组合迭代的结果。您每次都完全重新分配tempf
。
考虑改变
#tempf <- dataset_with_key
tempf <- dataset_with_key[0,]
创建一个空数据框。然后在你的外观循环中,改变
#tempf <- dataset_with_key[dataset_with_key$key %in% tempcond$key,]
tempf <- cbind(tempf, dataset_with_key[dataset_with_key$key %in% tempcond$key,])
请注意,我实际上并没有自己闪亮,所以我无法验证这是否有效,但我猜它至少会让你更接近解决问题。< / p>