0

我想根据 3 个不同的输入变量更新我的输出,但输出只是由“var”更新。我知道我应该更新“var”、“Group”和“Timepoint”的 data <- reactive({}) 函数,但我需要帮助!我尝试了多种方法,但都没有奏效!提前感谢您的支持。

> head(metab)
  Replicate Group Timepoint        M0       M1     M2 M3 M4
1         1  DM         0   462276966 18832499 123172  0  0
2         2  DM         0   389073706 16540080 104004  0  0
3         3  DM         0   440497937 18778082  74654  0  0
4         4  DM         0   339266538 14427218  89319  0  0
5         5  DM         0   476276612 20352483  51748  0  0
6         6  DM         0   392164060 16587310 111081  0  0

library(shiny)

metab<- read.csv("metab.csv")
metab[,c("M0","M1","M2","M3","M4")] <- sapply(metab[,c("M0","M1","M2","M3","M4")],as.numeric)

ui <- fluidPage(

titlePanel("weight Expectation"),
  selectInput("var",label="Choose an ...",choice=c("M0"=4,
                                                            "M1"=5,
                                                            "M2"=6,
                                                            "M3"=7,
                                                            "M4"=8), selectize=FALSE),

selectInput(inputId = "Group", label = strong("Group"),
            choices = unique(metab$Group),
            selected = "DM"),


selectInput(inputId = "Timepoint", label = strong("Timepoint"),
            choices = unique(metab$Timepoint),
            selected = 30),


  verbatimTextOutput("statistic"),
  plotOutput("box")
)

server <- function(input,output){

data <- reactive({
metab[,as.numeric(input$var)]

})

output$statistic <- renderPrint({
summary(data())
})

output$box <- renderPlot({
x<-summary(data())
boxplot(x,col="sky blue",border="purple")
})
}

shinyApp(ui = ui, server = server)

4

1 回答 1

0

这里没有真正需要整个reactive调用。您可以执行以下操作:

output$box <- renderPlot({
x <- metab[metab$Group == input$Group & metab$Timepoint == input$Timepoint, which(colnames(metab)==input$var)] 
x <- summary(x)
boxplot(x,col="sky blue",border="purple")
})

并在 renderPrint 中进行类似的更改

于 2021-06-01T19:49:26.297 回答