2015-01-11 34 views
5

में प्रतिक्रियाशील डेटा सेट को फ़िल्टर करना मुझे एक प्रतिक्रियाशील डेटा सेट को फ़िल्टर करने में कुछ परेशानी का सामना करना पड़ रहा है जो कई संख्यात्मक इनपुट में निर्भर है। क्या उपलब्ध कोई रास्ता है? मैंने नीचे एक समान कोड प्रदान किया है जो उस कार्य को दोहराता है जिसे मैं प्राप्त करने की कोशिश कर रहा हूं।चमकदार आर

ui.R 
library(shiny) 
shinyUI(fluidPage(
    titlePanel("abc"), 
    sidebarLayout(
    sidebarPanel(
     numericInput("first", "A",0), 
     numericInput("second", "B",0), 
     numericInput("third", "C",0), 
     numericInput("fourth", "D",0), 
     numericInput("fifth", "E",0), 
     actionButton("mybutton","Submit") 
    ), 
    mainPanel(
     tableOutput("mytable") 
    ) 
) 
)) 



server.R 

library(data.table) 
library(shiny) 
library(stats) 
shinyServer(function(input, output) { 
    a<-c("A","B","C","D","E","F","G") 
    b<-c("10","20","30","40","50","60","70") 
    ab<-data.frame(a,b) 
    a<-c("A","B","C","D","E") 
    input_vector<-reactive({ 
    c(input$first,input$second,input$third,input$fourth,input$fifth) 
    }) 
    newdata<-reactive({ 
    data.frame(a,input_vector()) 
    }) 
    merged_data<-reactive({ 
    merge(newdata(),ab,by.newdata=a) 
    }) 
    mutated_data<-reactive({ 
    library(dplyr) 
    merged_data%>%              #using merged()%>% gives error "Warning in Ops.factor(function() : ‘*’ not meaningful for factors" 
     mutate(newvalue=input_vector*b)         #using merged%>% gives error "no applicable method for 'mutate_' applied to an object of class "reactive" 
    }) 
    output$mytable<-renderTable({ 
    input$mybutton 
    isolate(mutated_data()) 
    }) 

}) 

उत्तर

9

मुझे लगता है कि यह तुम क्या चाहते है:

library(data.table) 
library(shiny) 
library(stats) 

shinyServer(function(input, output) { 
    a<-c("A","B","C","D","E","F","G") 
    #b<-c("10","20","30","40","50","60","70") 
    b<-c(10,20,30,40,50,60,70) 
    ab<-data.frame(a,b) 
    a<-c("A","B","C","D","E") 

    input_vector<-reactive({ 
    c(input$first,input$second,input$third,input$fourth,input$fifth) 
    }) 
    newdata<-reactive({ 
    data.frame(a,input_vector()) 
    }) 
    merged_data<-reactive({ 
    merge(newdata(),ab,by.newdata=a) 
    }) 
    mutated_data<-reactive({ 
    library(dplyr) 
    mutate(merged_data(),newvalue=input_vector()*b)      
    }) 

    output$mytable<-renderTable({ 
    input$mybutton 
    isolate(mutated_data()) 
    }) 


}) 

enter image description here

+0

धन्यवाद माइक। यह वास्तव में बहुत उपयोगी था। बस मैं क्या चाहता था। –

+0

ऐसा लगता है कि 'पृथक (...) '' mutated_data() 'के आसपास कोई प्रभाव नहीं है ...? – d8aninja

+1

हां, इसका एक बड़ा प्रभाव पड़ता है। अर्थात् जब आप ए, बी, सी, डी, ई मानों को अपडेट करते हैं तो यह तुरंत चमक को आउटपुट को अपडेट करने से रोकता है। अन्यथा एक सबमिट बटन की आवश्यकता नहीं होगी। ऐसा करने का एक और तरीका 'eventReactive' का उपयोग करना होगा जो अलग से बच जाएगा। –

संबंधित मुद्दे