Я создал функцию для расчета прогнозируемых значений по 3 переменным.
Однако я не могу настроить функцию renderValueBox
для выполнения расчетов.
Код здесь (write in rmarkdown
):
---
title: "Untitled"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
theme: cosmo
---
```{r}
library(tidyverse)
df_2 <- data.frame(
m = seq(from = .05, to = .95, by = .05),
d = seq(from = .04, to = .94, by = .05),
q = c(1:18, 2000)
)
desconto <- function(mc, desc, qtde) {
((((mc) / (mc - desc)) - 1) * qtde + qtde)
}
price <- desconto(
mc = df_2$m,
desc = df_2$d,
qtde = df_2$q
)
```
```{r}
library(shiny)
library(flexdashboard)
```
```
Predict values
=================================
Sidebar{.sidebar data-width=300}
---------------------------------
```{r}
# Widgets
sliderInput(
inputId = 'm', label = 'mc',
value = mean(round(x = df_2$m, digits = 0)) * 100,
min = min(round(x = df_2$m, digits = 0)) * 100,
max = max(round(x = df_2$m, digits = 0)) * 100
)
sliderInput(
inputId = 'd', label = 'dc',
value = mean(round(x = df_2$d, digits = 0)) * 100,
min = min(round(x = df_2$d, digits = 0)) * 100,
max = max(round(x = df_2$d, digits = 0)) * 100
)
numericInput(
inputId = 'q', label = 'qtde',
value = mean(round(x = df_2$q, digits = 0)),
min = min(round(x = df_2$q, digits = 0)),
max = max(round(x = df_2$q, digits = 0))
)
```
```{r}
# Reactive object
reac_1 <- reactive({
tibble(
m = input$m,
d = input$d,
q = input$q
)
})
# Reactive output
pred_4 <- reactive({
x = reac_1()$price
})
```
Calculator{}
----------------------
```{r}
renderValueBox(
valueBox(
value = pred_4()
)
)
```
Например, для mc = 50
, dc = 20
и qtde = 1500
ожидаемый результат будет 2500
.
- Проблема находится в функции
renderValueBox
Спасибо большое.