0

作为一项学习练习,我正在尝试将基本的闪亮应用示例(Old Faithful Geyser 发行版)转换为弹性仪表板布局。关于为什么这不显示情节的任何想法?是否需要单独引用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")
})
```

如果我得到这个工作,将继续工作并报告。

4

2 回答 2

2

您可以通过将直方图绘图移动到单独的部分并删除server第一个块中的代码来实现这一点。这不会使用@sandipan 方法中的单独ui和闪亮的模块。server

---
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')

  })
```

在此处输入图像描述

于 2016-12-23T18:45:09.613 回答
1

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

    ---
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)
```

在此处输入图像描述

于 2016-12-23T18:36:28.330 回答