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

时间:2016-12-23 17:45:55

标签: r shiny flexdashboard

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

如果我开始工作,将继续处理此事并报告回来。

2 个答案:

答案 0 :(得分:2)

您可以通过将直方图绘制移动到单独的部分并删除第一个块中的.navbar .navbar-nav { display: inline-block; float: none; vertical-align: top; } .navbar .navbar-collapse { text-align: center; } 代码来实现此目的。这不会在@ sandipan的方法中使用单独的serverui闪亮模块。

server

enter image description here

答案 1 :(得分: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)
```

enter image description here