'What is the best way to convert flexdashboard to a Shiny (ui, server)?

I have a flexdashboard application and I would like to convert it into two parts: ui and server.

Is there any way (functions or workaround) to do this?

A simple flexdashboard document:

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(dplyr)
library(tibble)
```

```{r}
UF = c('AC', 'AM', 'AP', 'BA', 'CE', 'ES', 'PB', 'PE', 'AC', 'AC', 'AP')
Coluna = c(30, 200, 7, 12, 854, 2, 78, 965, 12, 22, 12)
id = 1:11
df <- data.frame(UF,Coluna,id)

df_2 <- df %>% 
  group_by(UF) %>% 
  mutate(.data = ., soma_1 = sum(Coluna), soma_2 = sum(id), 
         media_1 = mean(Coluna), media_2 = mean(id)) %>% 
  distinct(.data = ., UF, .keep_all = TRUE)

f_1 <- function(x) {
  df_2$Coluna[df_2$UF == x]
}

reac <- reactive({
  tibble(
    input$UF
  )
})

pred <- reactive({
  temp <- reac()
  input$UF
})
```

side1{.sidebar}
---------------------------------

**Control panel**

```{r}
selectInput(
  inputId = "UF",
  label="Unidade federativa:",
  choices = unique(df_2$UF),
  selected = ""
)
```

calc1{}
---------------------------------

###
```{r}
renderValueBox({
  expr = valueBox(
    value = f_1(x = pred()), 
    caption = "Coluna", 
    color = "#008bbb", 
    icon = "fa-users"
  )
})
```

I tried using the following code (in RScript) in many ways, but the document was not rendered.

library(flexdashboard)
library(shiny)
library(dplyr)
library(tibble)

file <- 'example.Rmd'
dir <- dirname(file)

ui <- rmarkdown:::rmarkdown_shiny_ui(dir, file)
render_args <- list()
render_args$envir <- parent.frame()
server <- rmarkdown:::rmarkdown_shiny_server(dir, file, 'UTF-8', T, render_args)

shinyApp(ui, server)

In fact, I don't even know if the code above lends itself to this, as I didn't understand them very well.

Error message:

Error in rmarkdown:::rmarkdown_shiny_server(dir, file, "UTF-8", T, render_args) : unused argument (render_args)

But, in addition to this function above, are there other ways to do this conversion?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source