2015-01-11 7 views
5

いくつかの数値入力に依存する反応性データセットをフィルタリングする際に問題が発生しています。私は達成しようとしているタスクを複製する以下の同様のコードを提供しました。光沢のある反応性データのフィルタリングR

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()'の周りに 'isolate(...)'のような効果はありません...? – d8aninja

+1

はい、大きな効果があります。つまり、A、B、C、D、Eの値を更新するとすぐに、輝きが右の出力を更新するのを防ぎます。それ以外の場合は、送信ボタンは必要ありません。これを行う別の方法は、分離を避ける 'eventReactive'を使うことです。 –

関連する問題