从 R shiny 中的选定输入过滤
Filtering from selected input in R shiny
尝试根据选定的输入过滤数据库时,我总是遇到错误。我基于 iris 数据集做了这个非常简单的例子来向你们展示我的问题:
```{r}
library(flexdashboard)
library(tidyverse)
```
Sidebar {.sidebar}
=====================================
```{r}
fluidRow(
column(7,
selectInput("Species", "Choose a species",
choices = c("setosa", "versicolor", "virginica"))))
mydata <- reactive({
iris %>% filter(Species == input$Species)
})
```
Results
=====================================
```{r}
head(mydata)
```
由于 mydata
是反应式,您必须在反应式上下文中使用 mydata()
对其进行评估(例如 renderDT
)。有关详细信息,请参阅 flexdashboard with shiny and a shiny tutorial。
---
title: "test"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: bootstrap
---
```{r global, include = FALSE}
library(flexdashboard)
library(tidyverse)
library(DT)
```
Sidebar {.sidebar}
=====================================
```{r}
fluidRow(
column(7,
selectInput("Species", "Choose a species",
choices = c("setosa", "versicolor", "virginica"))))
mydata <- reactive({
iris %>% filter(Species == input$Species)
})
```
Results
=====================================
```{r}
renderDT({head(mydata())})
```
尝试根据选定的输入过滤数据库时,我总是遇到错误。我基于 iris 数据集做了这个非常简单的例子来向你们展示我的问题:
```{r}
library(flexdashboard)
library(tidyverse)
```
Sidebar {.sidebar}
=====================================
```{r}
fluidRow(
column(7,
selectInput("Species", "Choose a species",
choices = c("setosa", "versicolor", "virginica"))))
mydata <- reactive({
iris %>% filter(Species == input$Species)
})
```
Results
=====================================
```{r}
head(mydata)
```
由于 mydata
是反应式,您必须在反应式上下文中使用 mydata()
对其进行评估(例如 renderDT
)。有关详细信息,请参阅 flexdashboard with shiny and a shiny tutorial。
---
title: "test"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: bootstrap
---
```{r global, include = FALSE}
library(flexdashboard)
library(tidyverse)
library(DT)
```
Sidebar {.sidebar}
=====================================
```{r}
fluidRow(
column(7,
selectInput("Species", "Choose a species",
choices = c("setosa", "versicolor", "virginica"))))
mydata <- reactive({
iris %>% filter(Species == input$Species)
})
```
Results
=====================================
```{r}
renderDT({head(mydata())})
```