gpt4 book ai didi

r - Flex 仪表板 : Input and Outputs in different tabs

转载 作者:行者123 更新时间:2023-12-01 08:01:43 26 4
gpt4 key购买 nike

我是一个使用 flex-dashboards 的新手...
如何在两个不同的选项卡中将输入信息和输出结果分开?这是一个简单的例子,我试图在第二个选项卡“输出”中只渲染条形图

---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
data(WorldPhones)
```

Inputs
=======================================================================

```{r, include=FALSE}
# Shiny module definition (would typically be defined in a separate R script)

# UI function
worldPhonesUI <- function(id) {
ns <- NS(id)
fillCol(height = 600, flex = c(2, 1),
inputPanel(
selectInput(ns("region"), "Region1:", choices = colnames(WorldPhones))
)
)
}

# Server function
worldPhones <- function(input, output, session) {
output$phonePlot <- renderPlot({
barplot(WorldPhones[,input$region]*1000,
ylab = "Number of Telephones", xlab = "Year")
})
}
```

```{r, eval=TRUE}
# Include the module
worldPhonesUI("phones")
callModule(worldPhones, "phones")
```

Results
=======================================================================

```{r}
worldPhonesUI <- function(id) {
ns <- NS(id)
fillCol(height = 600, flex = c(NA, 1),
plotOutput(ns("phonePlot"), height = "80%")
)
}
```

最佳答案

您忘记了有关 ui 和服务器功能的所有内容,并直接将对象放入夹盘中,如下所示:

---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
data(WorldPhones)
```

Inputs
=======================================================================

```{r}

selectInput("region", "Region1:", choices = colnames(WorldPhones))

```

Results
=======================================================================

```{r}
renderPlot({
barplot(WorldPhones[,input$region]*1000,
ylab = "Number of Telephones", xlab = "Year")
})

```

关于r - Flex 仪表板 : Input and Outputs in different tabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40812291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com