你好,stackoverflow 社区。 ,
我正在尝试通过闪亮的应用程序创建和呈现 .rmd 文件。
“在我的本地机器(ubuntu 18.04)上,这按预期工作。'
但是在我的服务器(Ubuntu 20.04.2 LTS)上,即使安装了所有依赖项,
它:
我做了这个最小的reprex:
library(shiny)
library(base64enc)
ui <- fluidPage(
# Application title
titlePanel("renderRMD"),
# Sidebar
sidebarLayout(
sidebarPanel(
h3("create an empty file:"),
actionButton("rmd", "create an RMD"),
h3("populate file"),
textInput("title","add title",value = "Some Title"),
textInput("txt","add text", value ="The docs content"),
actionButton("sub", "submit Text and Title"),
h3("render RMD:"),
actionButton("render", "Render"),
h3("View pdf"),
actionButton("prev", "View pdf")
),
# Show the pdf:
mainPanel(
uiOutput("pdf")
)
)
)
# Define server logic
server <- function(input, output) {
# create an empty rmd
observeEvent(input$rmd, {
file.create("www/test.rmd")
})
# populate file
observeEvent(input$sub,{
cat(
paste("---","\ntitle:",
input$title,
'\nauthor: "Author"\noutput: pdf_document\n---\n',
input$txt),
file= "www/test.rmd")
})
# render file:
observeEvent(input$render,{
rmarkdown::render(input = "www/test.rmd")
})
# View pdf:
observeEvent(input$prev, {
output$pdf <- renderUI({
pdf_file_path <- "www/test.pdf"
b64 <- dataURI(file = pdf_file_path, mime = "application/pdf")
tags$iframe(
style = "height: 600px; width: 100%;", src = b64
)
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
这是 Shine-server 开源版本的限制,还是可能与 linux 上的权限有关?
更新:
$ sudo chown -R shiny:shiny ./www
修复了 file.create 和 cat() 的权限 , 然而 render() 仍然不起作用:
感谢您的建议!