将基本的闪亮应用程序转换为灵活的仪表板布局

Converting basic shiny app to flex dashboard layout

作为学习练习,我正在尝试将基本的闪亮应用程序示例 (Old Faithful Geyser distribution) 转换为灵活的仪表板布局。关于为什么这不显示情节的任何想法?是否需要单独引用server.R文件中的函数?

完整代码如下:

---
title: "DistBins"
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(shiny)
library(datasets)
data("faithful")

shinyServer(function(input, output) {

  output$distPlot <- renderPlot({

    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')

  })

})
```

Column {.sidebar}
-----------------------------------------------------------------------

Adjust number of bins within distribution

```{r}
sliderInput("bins",
                   "Number of bins:",
                   min = 1,
                   max = 50,
                   value = 30)

```

Column
-----------------------------------------------------------------------

### Distribution

```{r}
# Define server logic required to draw a histogram
renderPlot({
  plotOutput("distPlot")
})
```

我会继续努力,如果我成功了,会回来报告。

您的代码的以下修改有效:

    ---
title: "DistBins"
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(shiny)
library(datasets)
data("faithful")

server <- function(input, output) {

  output$distPlot <- renderPlot({

    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')

  })

}
```

Column {.sidebar}
-----------------------------------------------------------------------

Adjust number of bins within distribution

```{r}
ui = fluidPage(
    sliderInput("bins",
                   "Number of bins:",
                   min = 1,
                   max = 50,
                   value = 30),
    # Define server logic required to draw a histogram
    plotOutput("distPlot")
  )
```

Column
-----------------------------------------------------------------------

### Distribution

```{r}
# run shiny app
shinyApp(ui = ui, server = server)
```

您只需将直方图移到单独的部分并删除第一个块中的 server 代码即可实现此目的。这不会在@sandipan 的方法中使用单独的 uiserver 闪亮模块。

---
title: "DistBins"
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(shiny)
library(datasets)
data("faithful")
```

Column {.sidebar}
-----------------------------------------------------------------------

Adjust number of bins within distribution

```{r}
sliderInput("bins",
                   "Number of bins:",
                   min = 1,
                   max = 50,
                   value = 30)

```

Column
-----------------------------------------------------------------------

### Distribution

```{r}
# draw a histogram
renderPlot({

    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')

  })
```