在闪亮的 R 中过滤反应数据集
Filtering reactive data set in shiny 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())
})
})
我想这就是你想要的:
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())
})
})
我在过滤依赖于多个数字输入的反应数据集时遇到了一些麻烦。有什么可用的方法吗?我在下面提供了一个类似的代码,它复制了我正在尝试实现的任务。
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())
})
})
我想这就是你想要的:
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())
})
})