【问题标题】:Is there a way to use Shiny datatables to do calculations with formulas like excel?有没有办法使用 Shiny 数据表使用 Excel 等公式进行计算?
【发布时间】:2021-10-20 01:12:54
【问题描述】:
我已经在网上搜索了 Shiny 数据表的用途,但到目前为止,我没有发现任何东西可以让我使用 Shiny 数据表和嵌入在整个列中的公式,以便我可以编辑变量,并且整个列会发生变化?
看起来有点像这样:
利率(可变):0.5%
| Name |
Base Debt |
Debt w/ Interest |
| John |
1000 |
1005 |
| Mary |
2000 |
2010 |
其中带利息的债务将通过基础债务 * 1+利息来计算,并且利率将是一个单独设置的变量。
如果已经回答,请告诉我!
【问题讨论】:
标签:
r
dataframe
shiny
datatable
dt
【解决方案1】:
1 小时后又是我……输入可以使用服务器端的公式进行操作,例如:
library(shiny)
library(xts)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
numericInput("var", "Var",2),
),
mainPanel(
tableOutput("data")
)
)
)
server <- function(input, output) {
output$data <- renderTable({
# VOL 20 error handling
NA_rows <- which(tabl$Num1 == "#N/A")
tabl$Num1[NA_rows] <- 1
# Calculations
tabl$'Num1 * Num2 * Var' <- tabl$Num1 * tabl$Num2 * input$var
tabl
}, bordered=TRUE, digits=5)
}
shinyApp(ui, server)