我有一个闪亮的应用程序,单击按钮后会打印报告。报告创建是通过 downloadHandler() 函数进行的。
我希望在导出报告之前有一个强制输入字段;合适的 Shiny 函数是 validate() ( https://shiny.rstudio.com/articles/validation.html )。
但是,根据文档,validate()函数只能在reactive()或render()函数中使用:
To use this validation test in your app, place it at the start of any reactive or render* expression that calls input$data.
Run Code Online (Sandbox Code Playgroud)
我找不到可以将此函数放入 downloadHandler 函数中的位置。有谁知道这怎么可能?
这是相关代码部分;我希望创建报告时必须填写“company_name”字段。
ui <- fluidPage(
sidebarLayout(
position = "left",
sidebarPanel(
textInput(
inputId = "company_name",
label = "Company name",
value = ""
),
)
)
)
server <- function(input, output) {
output$report <- downloadHandler(
filename = "report.pdf",
content = function(file) {
# Copy the report file …Run Code Online (Sandbox Code Playgroud) 我想根据前一行和同一列的值逐步增加一个新列。你可以用一个循环来做,就像这样:
df <- data.frame(a = 2000:2010,
b = 10:20,
c = seq(1000, 11000, 1000),
x = 1000)
for(i in 2:nrow(df)) df$x[i] <- (df$c[i]) * df$a[i-1] / df$x[i-1] + df$b[i] * df$a[i]
df
a b c x
1 2000 10 1000 1000.00
2 2001 11 2000 26011.00
3 2002 12 3000 24254.79
4 2003 13 4000 26369.16
5 2004 14 5000 28435.80
6 2005 15 6000 30497.85
7 2006 16 7000 32556.20
8 2007 17 8000 34611.93
9 2008 18 9000 …Run Code Online (Sandbox Code Playgroud)