I am facing some trouble in filtering a reactive data set which is dependent in several numeric inputs. Is there any way around available?I have provided a similar code below which replicates the task I am trying to achieve.
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())
})
})
I think this is what you want:
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())
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With