根据选择的输入显示图形
Display graphic according to selected input
我想根据在第一个选项卡中选择的输入在另一个选项卡中显示图形。
对于“auto”,我想在 TAB B 中显示一个图形(名为“graph_auto”),如果选择“boat”,我想显示另一个图形(名为“graph_boat") 在 TAB 中 B.This 我做了什么 :
---
title: "my report"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(htmltools)
library(flextable)
library(plotly)
```
RESULTS
=======================================================================
Column
-----------------------------------------------------------------------
### TAB A
```{r}
# creation du tibble sur ce KPI
my_data = data.frame(product = rep(c("auto", "boat"),each=2),
year = c("2009", "2011", "2005", "2019"),
price = c("10 000", "20 000", "7 000", "60 000"),
speed = c("220", "250", "70", "140"))
ui <- fluidPage(
selectInput("product", "", choices = my_data$product),
uiOutput("tbl")
)
server <- function(input, output, session) {
output$tbl <- renderUI( {
out <- subset(my_data, product ==input$product)
library(flextable)
htmltools_value((flextable(out)))
})
}
shinyApp(ui, server)
```
Column
-----------------------------------------------------------------------
### TAB B
```{r}
# if "auto" is selected, then display this graphic
graph_auto <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
# if "boat" is selected, then display this graphic
graph_boat <- plot_ly(midwest, x = ~percollege, type = "box", width = 600, height = 400)
```
但我无法根据所选产品显示图形。我们如何从另一个选项卡访问选定的输入?一些帮助将不胜感激
这是您的想法吗(请注意,第一个情节不起作用)?
---
title: "my report"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
runtime: shiny
---
```{r setup, include=FALSE}
library(htmltools)
library(flextable)
library(plotly)
my_data = data.frame(product = rep(c("auto", "boat"),each=2),
year = c("2009", "2011", "2005", "2019"),
price = c("10 000", "20 000", "7 000", "60 000"),
speed = c("220", "250", "70", "140"))
```
RESULTS
=======================================================================
Column
-----------------------------------------------------------------------
### TAB A
```{r}
selectInput("product", "", choices = my_data$product)
renderUI({
out <- subset(my_data, product ==input$product)
htmltools_value((flextable(out)))
})
```
Column
-----------------------------------------------------------------------
### TAB B
```{r}
# if "auto" is selected, then display this graphic
renderPlotly({
if (input$product == "auto") {
plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
}
# if "boat" is selected, then display this graphic
if (input$product == "boat") {
plot_ly(midwest, x = ~percollege, type = "box", width = 600, height = 400)
}
})
```
您不需要在 flexdashboard
中实际包含闪亮应用程序的结构,而只需包含单个 UI/render
元素。看看 the help page.
我想根据在第一个选项卡中选择的输入在另一个选项卡中显示图形。
对于“auto”,我想在 TAB B 中显示一个图形(名为“graph_auto”),如果选择“boat”,我想显示另一个图形(名为“graph_boat") 在 TAB 中 B.This 我做了什么 :
---
title: "my report"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(htmltools)
library(flextable)
library(plotly)
```
RESULTS
=======================================================================
Column
-----------------------------------------------------------------------
### TAB A
```{r}
# creation du tibble sur ce KPI
my_data = data.frame(product = rep(c("auto", "boat"),each=2),
year = c("2009", "2011", "2005", "2019"),
price = c("10 000", "20 000", "7 000", "60 000"),
speed = c("220", "250", "70", "140"))
ui <- fluidPage(
selectInput("product", "", choices = my_data$product),
uiOutput("tbl")
)
server <- function(input, output, session) {
output$tbl <- renderUI( {
out <- subset(my_data, product ==input$product)
library(flextable)
htmltools_value((flextable(out)))
})
}
shinyApp(ui, server)
```
Column
-----------------------------------------------------------------------
### TAB B
```{r}
# if "auto" is selected, then display this graphic
graph_auto <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
# if "boat" is selected, then display this graphic
graph_boat <- plot_ly(midwest, x = ~percollege, type = "box", width = 600, height = 400)
```
但我无法根据所选产品显示图形。我们如何从另一个选项卡访问选定的输入?一些帮助将不胜感激
这是您的想法吗(请注意,第一个情节不起作用)?
---
title: "my report"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
runtime: shiny
---
```{r setup, include=FALSE}
library(htmltools)
library(flextable)
library(plotly)
my_data = data.frame(product = rep(c("auto", "boat"),each=2),
year = c("2009", "2011", "2005", "2019"),
price = c("10 000", "20 000", "7 000", "60 000"),
speed = c("220", "250", "70", "140"))
```
RESULTS
=======================================================================
Column
-----------------------------------------------------------------------
### TAB A
```{r}
selectInput("product", "", choices = my_data$product)
renderUI({
out <- subset(my_data, product ==input$product)
htmltools_value((flextable(out)))
})
```
Column
-----------------------------------------------------------------------
### TAB B
```{r}
# if "auto" is selected, then display this graphic
renderPlotly({
if (input$product == "auto") {
plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
}
# if "boat" is selected, then display this graphic
if (input$product == "boat") {
plot_ly(midwest, x = ~percollege, type = "box", width = 600, height = 400)
}
})
```
您不需要在 flexdashboard
中实际包含闪亮应用程序的结构,而只需包含单个 UI/render
元素。看看 the help page.