r - Using dplyr filter in a Shiny app -


i'm in stages of building shiny app plot data based on user selections. data begins:

price,mileage,make,model,trim,type,cylinder,liter,doors,cruise,sound,leather 17314.10313,8221,buick,century,sedan 4d,sedan,6,3.1,4,1,1,1 17542.03608,9135,buick,century,sedan 4d,sedan,6,3.1,4,1,1,0 16218.84786,13196,buick,century,sedan 4d,sedan,6,3.1,4,1,1,0 16336.91314,16342,buick,century,sedan 4d,sedan,6,3.1,4,1,0,0 16339.17032,19832,buick,century,sedan 4d,sedan,6,3.1,4,1,0,1 15709.05282,22236,buick,century,sedan 4d,sedan,6,3.1,4,1,1,0 15230.00339,22576,buick,century,sedan 4d,sedan,6,3.1,4,1,1,0 15048.04218,22964,buick,century,sedan 4d,sedan,6,3.1,4,1,1,0 14862.09387,24021,buick,century,sedan 4d,sedan,6,3.1,4,1,0,1 15295.01827,27325,buick,century,sedan 4d,sedan,6,3.1,4,1,1,1 21335.85248,10237,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,0,0 20538.08751,15066,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,0 20512.09409,16633,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,0 19924.15905,19800,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,1 19774.24907,23359,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,1 19344.16554,23765,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,0 19105.13012,24008,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,0,0 18543.42705,26034,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,1 17808.199,32896,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,0 17968.83828,34665,buick,lacrosse,cx sedan 4d,sedan,6,3.6,4,1,1,1 22358.87768,8970,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,1,0 23785.92253,10577,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,1,1 22926.09037,14363,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,1,1 21895.75878,16508,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,0,1 21273.06171,18908,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,0,0 21460.01395,19467,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,0,1 21183.12359,21394,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,0,0 20406.0995,22596,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,0,0 21058.13958,24469,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,1,1 19556.89932,25245,buick,lacrosse,cxl sedan 4d,sedan,6,3.6,4,1,0,0 23447.68656,15755,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,1,0 23547.23944,16235,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,1,0 23016.00801,18147,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,1,1 22230.0275,22102,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,0,1 22625.07357,23612,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,0,1 21799.1721,24439,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,0,0 21341.25721,25212,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,1,1 21683.03146,26779,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,1,0 20986.01602,27096,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,0,0 20902.10379,29649,buick,lacrosse,cxs sedan 4d,sedan,6,3.8,4,1,1,1 20698.07708,2992,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,0,1 20099.25684,10036,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,1 18145.12649,18339,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,0 17944.85692,19592,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,0,0 19027.86231,21797,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,0,1 18348.89857,23852,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,0 17750.88457,25040,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,0 17772.96968,25052,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,0 17394.0214,25464,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,0 17645.74504,27830,buick,lesabre,custom sedan 4d,sedan,6,3.8,4,1,1,1 21908.36662,17353,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,0,0 21956.34266,17787,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,0 21646.11692,19562,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,1 21575.45683,20137,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,0 20952.2178,20158,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,0 21562.04758,23767,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,0,1 19981.12791,24323,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,0 19425.84862,27839,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,0 19191.98962,29187,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,1 19641.7419,31324,buick,lesabre,limited sedan 4d,sedan,6,3.8,4,1,1,1 25589.98315,2308,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,0 25098.62906,10014,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,0 23420.70695,18910,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,0,1 22661.04849,20105,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,0,0 23493.0823,20453,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,0 22435.20282,22287,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,1 21878.12,23237,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,0 23077.56591,23798,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,0,1 21698.01475,25489,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,1 21831.82292,25564,buick,park avenue,sedan 4d,sedan,6,3.8,4,1,1,1 26831.19404,4695,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,1,0 26060.33535,9795,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,1,0 26781.81465,12052,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,1,0 26302.07428,13050,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,1,0 26190.27147,17335,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,0,1 25508.21096,17480,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,1,0 23348.01695,24027,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,0,1 23406.68982,25387,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,0,1 23159.54378,25869,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,0,0 21536.74173,37128,buick,park avenue,special ed ultra 4d,sedan,6,3.8,4,1,1,1 51154.04722,2202,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,1,1 49248.15897,6685,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,0,1 46747.67327,15343,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,1,1 44130.61706,21341,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,0,1 44084.91421,21367,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,1,1 43892.46788,23371,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,0,1 44300.63996,23751,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,0,1 42677.60112,24052,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,0,1 43374.05242,25199,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,1,1 40619.07227,30082,cadillac,cst-v,sedan 4d,sedan,8,5.7,4,1,1,1 33417.96501,6598,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 30957.08075,10625,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 31431.13037,11013,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 30781.51563,14937,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 30646.4377,17094,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 30792.14903,17870,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 30392.75016,18449,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 28817.08185,21039,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,0,1 29275.20871,21056,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 28040.12853,27484,cadillac,cts,sedan 4d,sedan,6,2.8,4,1,1,1 39801.55135,14095,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 40335.73731,14743,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 39307.00916,16041,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 38600.23956,17138,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 38445.89717,18661,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 36077.79612,21966,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 35866.58271,24415,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,1,1 35338.65369,25163,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 36154.30355,25339,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,1,1 34685.66298,25421,cadillac,deville,dhs sedan 4d,sedan,8,4.6,4,1,0,1 42820.32902,5499,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 41378.04809,8125,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 40856.3909,12791,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,1,1 41419.03726,14452,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 37510.25357,21593,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 37215.16938,22211,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 36332.89469,25153,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 36245.15823,26250,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,1,1 32954.14134,36074,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,0,1 32537.18675,41829,cadillac,deville,dts sedan 4d,sedan,8,4.6,4,1,1,1 35715.76856,6447,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,0,1 35651.68002,10555,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,1,1 35129.34077,11975,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,1,1 35165.75937,13449,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,1,1 32501.24519,17508,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,0,1 33220.02845,18661,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,0,1 32509.47829,20910,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,0,1 31132.21349,23124,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,1,1 31181.71516,26222,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,0,1 31059.18103,27544,cadillac,deville,sedan 4d,sedan,8,4.6,4,1,1,1 42741.52367,2846,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,0,1 40966.60741,7476,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,1,1 38795.37909,13973,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,1,1 38297.46254,16754,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,0,1 37192.89637,19100,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,0,1 36210.123,21778,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,0,1 36633.63382,22042,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,1,1 35895.49941,23056,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,1,1 34974.37804,25796,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,1,1 32038.33956,35326,cadillac,sts-v6,sedan 4d,sedan,6,3.6,4,1,1,1 48310.32954,788,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,0,1 48365.9809,2616,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,1,1 45061.95194,13829,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,1,1 44205.87588,15104,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,0,1 42377.95544,18581,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,0,1 41671.58314,20575,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,0,1 41516.42986,23861,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,1,1 41053.48217,25717,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,1,1 38208.50102,31303,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,1,1 39072.39205,31587,cadillac,sts-v8,sedan 4d,sedan,8,4.6,4,1,0,1 70755.46672,583,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 68566.18719,6420,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 69133.73172,7892,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 66374.30704,12021,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 65281.48124,15600,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 63913.11725,18200,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 60567.54909,23193,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 57154.44344,29260,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 55639.08765,31805,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,0,1 52001.99438,42691,cadillac,xlr-v8,hardtop conv 2d,convertible,8,4.6,2,1,1,1 12146.18803,10011,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,0,1 12163.82042,12101,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,0,1 11472.02276,19699,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,0,1 11017.16871,20100,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,1,0 11096.85727,20334,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,1,0,0 10386.04022,22225,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,0,0 11137.04565,22484,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,1,1 11045.10884,24568,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,1,0,1 10777.05254,27906,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,0,0 9928.188175,29680,chevrolet,aveo,ls hatchback 4d,hatchback,4,1.6,4,0,0,1 12649.11089,3629,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,0,1,0 12314.59122,4142,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,0,1,0 11318.00809,11156,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,0,1,1 12409.94909,11981,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,1,1,1 11555.2674,13404,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,1,1,0 11700.11149,15253,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,1,0,0 11215.01865,19945,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,0,0,0 10144.95208,23963,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,1,1,0 10491.0752,30948,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,0,1,0 9954.054174,37345,chevrolet,aveo,ls sedan 4d,sedan,4,1.6,4,0,1,1 11031.12993,20156,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,0,1,1 11343.05401,20186,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,1,1,1 11391.21372,21421,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,0,1,1 11247.86253,21427,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,1,1,1 10921.94537,23119,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,0,1,1 11179.95357,23121,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,0,1,1 11394.8864,25107,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,0,1,1 11070.06064,25476,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,0,1,1 11013.87137,25746,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,1,1,1 11115.01364,30056,chevrolet,aveo,lt hatchback 4d,hatchback,4,1.6,4,1,1,1 11918.45607,7278,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,0,0 12408.80615,10213,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,0,1 11302.90299,14627,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,1,0 11615.02102,19014,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,1,1 10805.13009,21013,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,1,1,1 11169.91839,22380,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,1,0 10770.10655,25065,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,1,0 10872.01393,25869,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,0,0 10921.94537,27776,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,1,0,0 9919.048185,34621,chevrolet,aveo,lt sedan 4d,sedan,4,1.6,4,0,1,0 10813.34352,266,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,1,0,1 11167.861,4716,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,1,1,0 10897.07651,6699,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,0,1,1 10106.01643,14200,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,1,0,0 10354.04385,14521,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,0,1,0 10287.97736,16521,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,1,1,1 9720.97889,20836,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,1,1,0 9506.047937,22169,chevrolet,aveo,svm hatchback 4d,hatchback,4,1.6,4,0,0,1 

the whole thing big post, should sufficient.

my ui.r file contains

library(shiny)   data <- read.csv("amstat.csv", header = true) modeltypes <- unique(data$model)  # define ui application draws histogram shinyui(fluidpage(    # application title   titlepanel("car prices"),    # sidebar slider input number of bins    sidebarlayout(     sidebarpanel(       selectinput("model",                    label = "choose model display",                   choices = modeltypes),        selectinput("price",                   label = "choose price",                   choices = list("left","center", "right"),                   selected="center")       ),      # show plot of generated distribution     mainpanel(        plotoutput("carpriceplot")     )   ) )) 

and server.r contains

library(shiny) library(magrittr) library(dplyr)  shinyserver(function(input, output) {    data <- read.csv("amstat.csv", header = true)   amstat1<-data %>% select(type,price,model )%>% filter(model == input$model)    output$carpriceplot <- renderplot({      plot(model,          price,          xlab="model",          ylab="prirce",          pch=20)    }) }) 

when try run app, error message

error in filter_impl(.data, dots) : operation not allowed without active reactive context. (you tried can done inside reactive expression or observer.)

i'm not grasping something. in other apps i've written try learn shiny i've accomplished same thing using subset instead of filter...should avoid filter in shiny? or doing wrong? well, i'm doing wrong!

when use variable ui (input$...), must in reactive:

shinyserver(function(input, output) {    data <- read.csv("amstat.csv", header = true)   amstat1<-reactive({     data %>% select(type,price,model ) %>% filter(model == input$model)     })    output$carpriceplot <- renderplot({     plot(amstat1()$model,          amstat1()$price,          xlab="model",          ylab="price",          pch=20)    }) }) 

Comments