从闪亮的反应数据框中提取值

Extract a value from reactive data frame in shiny

我不确定如何从反应性数据框中提取值并将其用于计算。无功输出没有出现,所以我无法计算出我最终想要什么。当我 运行 下面的脚本时,出现错误“$ operator is invalid for atomic vector”

Exercise<-c(A,B,C)
Var1<-c(60,90,50)
Var2<-c(0.5,0.7,0.3)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(numericInput(inputId = "Time1",
                              label = "Duration:",
                              min = 0,
                              max = 120,
                              value = 1),
                 selectInput(
                   inputId = "Drill1",
                   label = "Drill1",
                   choices = Exercise,
                   selected = "1")
    ),
    mainPanel(h3(textOutput("Power"))
    )
  )
)


server <- function(input, output) {
  d<- reactive({
    res<-T1 %>%
      filter(Exercise == input$Drill1)
    res
  })
  
  output$Power <- renderPrint({
    dataset <-d()
    Int<-dataset$Var1[dataset$Exercise == input$Drill1]
    results<-Time1*Int
    results
  })
}

非常感谢您的提前帮助。

我稍微整理了您的代码并 运行 在新的 R 会话中。不幸的是,我无法重现这个问题。下面的应用程序在我的机器上运行良好。

library(shiny)
library(dplyr)

T1 <- data.frame(
  Exercise = c("A", "B", "C"),
  Var1 = c(60, 90, 50),
  Var2 = c(0.5, 0.7, 0.3)
)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      numericInput(
        inputId = "Time1",
        label = "Duration:",
        min = 0,
        max = 120,
        value = 1
      ),
      selectInput(
        inputId = "Drill1",
        label = "Drill1",
        choices = T1$Exercise
      )
    ),
    mainPanel(h3(textOutput("Power")))
  )
)


server <- function(input, output) {
  d <- reactive({
    filter(T1, Exercise == input$Drill1)
  })
  
  output$Power <- renderPrint({
    dataset <- d()
    Int <- dataset$Var1[dataset$Exercise == input$Drill1]
    input$Time1*Int
  })
}

shinyApp(ui, server)