子集数据帧中存储为反应式表达式eventReactive的列

子集数据帧中存储为反应式表达式eventReactive的列,r,shiny,reactive-programming,R,Shiny,Reactive Programming,请原谅这个不可复制的例子。理论上的解决方案就行了。我想知道如何将存储在反应式表达式中的数据帧子集为一个特定列,分配一个唯一的输出id,并最终显示在UI中。这类似于访问数据帧的列,如:df$column\u name 我使用与UI中的actionButton()链接的eventReactive()将数据帧存储为一个称为data()的反应式表达式 环境中的代码: # dataframe with n columns and k rows df actionButton(inputId = "g

请原谅这个不可复制的例子。理论上的解决方案就行了。我想知道如何将存储在反应式表达式中的数据帧子集为一个特定列,分配一个唯一的输出id,并最终显示在UI中。这类似于访问数据帧的列,如:
df$column\u name


我使用与UI中的
actionButton()
链接的
eventReactive()
将数据帧存储为一个称为
data()
的反应式表达式

环境中的代码:

# dataframe with n columns and k rows
df 
actionButton(inputId = "go", label = "Update")
# create a reactive expression 'data()', a subsetted data.frame based on other reactive values

data() <- eventReactive( input$go, { df %>% filter(based on other reactive values) } )

output$output_id <- renderSomething( { code depends on data()$specific column })
UI:

# dataframe with n columns and k rows
df 
actionButton(inputId = "go", label = "Update")
# create a reactive expression 'data()', a subsetted data.frame based on other reactive values

data() <- eventReactive( input$go, { df %>% filter(based on other reactive values) } )

output$output_id <- renderSomething( { code depends on data()$specific column })
服务器:

# dataframe with n columns and k rows
df 
actionButton(inputId = "go", label = "Update")
# create a reactive expression 'data()', a subsetted data.frame based on other reactive values

data() <- eventReactive( input$go, { df %>% filter(based on other reactive values) } )

output$output_id <- renderSomething( { code depends on data()$specific column })
#创建一个反应式表达式'data()',一个基于其他反应式值的子集data.frame
data()%filter(基于其他反应值)})

输出$output_id可能是以下示例,回答了您的问题。UI有一个多选列表,列表的条目可用于对
iris
数据集的
Species
列进行子集设置

# Using multi select list to sum columns
library(shiny)
library(dplyr)
# Define UI for application that draws a histogram
ui <- fluidPage(
  # Application title
  titlePanel("Subset and sum a column of iris"),
   fluidRow(
     selectInput('Species', 'Species', levels(iris$Species), multiple = TRUE, selectize = FALSE)
   ),
   fluidRow(verbatimTextOutput('selection')),
  fluidRow(tableOutput('dataColumn')),
  fluidRow(
    tags$h2("sum:"),
    verbatimTextOutput('sum')
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  output$selection <- reactive(input$Species)
  subiris = reactive({
    subset(iris, Species %in% input$Species)
  })
  output$dataColumn <- renderTable(subiris()$Sepal.Length)
 output$sum <- renderPrint(sum(subiris()$Sepal.Length)) 
} 


# Run the application 
shinyApp(ui = ui, server = server)
#使用多选列表对列求和
图书馆(闪亮)
图书馆(dplyr)
#为绘制直方图的应用程序定义UI

谢谢你的回答,但这不是我要问的。在您的示例中,在
output$subdata中,我已经更新了解决方案,希望这对您有用。非常好。这真的和使用$1一样简单吗?