R 动态反应对象中基于图像和结果的降价报告问题

R 动态反应对象中基于图像和结果的降价报告问题,r,shiny,shiny-reactivity,R,Shiny,Shiny Reactivity,我想使用我的report.Rmd文件创建一个降价报告,但我有两个问题,第一,尽管smile image和report.Rmd在同一目录中,但使用(title:![smille.jpg](smille.jpg)**Happy Dash**找不到图像,另一个问题是R操作(如报告中使用被动对象的r unique(selectedvariable1()$DATA\u S2))无效。在我的示例中: # Packages library(shinythemes) library(lubridate) lib

我想使用我的
report.Rmd
文件创建一个降价报告,但我有两个问题,第一,尽管smile image和
report.Rmd
在同一目录中,但使用(
title:![smille.jpg](smille.jpg)**Happy Dash**
找不到图像,另一个问题是
R
操作(如报告中使用
被动对象的
r unique(selectedvariable1()$DATA\u S2)
)无效。在我的示例中:

# Packages
library(shinythemes)
library(lubridate)
library(dplyr)
library(anytime)
require(rmarkdown)
require(knitr)


# get AOI
download.file(
  "https://github.com/Leprechault/trash/raw/main/stands_example_v2.zip",
  zip_path <- tempfile(fileext = ".zip")
)
unzip(zip_path, exdir = tempdir())

# Open the files
setwd(tempdir())
stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
stands_ds <- stands_ds %>%
  mutate(DATA_S2 = ymd(DATA_S2))
stands_ds$PEST<-c(rep("A",34),rep("B",225))

# Create the shiny dash
ui <- fluidPage(
  theme = shinytheme("cosmo"),
  titlePanel(title="My Dash"),  
  sidebarLayout(
    sidebarPanel(
      selectInput(inputId = "selectedvariable0", "Type", choices = c(unique(stands_ds$PEST))),
      selectInput(inputId = "selectedvariable1", "Date",choices = NULL),
      selectInput(inputId = "selectedvariable2", "Project",choices = NULL),
      selectInput(inputId = "selectedvariable3", "Stand",choices = NULL),
      selectInput(inputId = "selectedvariable4", "ID-Unique",choices = NULL),
      downloadButton("download5", "Markdown Report",style = "margin-top: 10px; margin-bottom: 10px", class = "butt",style = "width:500px"),
      tags$head(tags$style(".butt{background-color:#034f84;} .butt{color: ##7CFC00;}"))
      
    ),
    mainPanel(
      textOutput("idSaida")
    )
  )
)

server <- function(input, output, session){
  
  
  selectedvariable0 <- reactive({
    filter(stands_ds, PEST == unique(stands_ds$PEST))
  })
  observeEvent(selectedvariable0(), {
    choices <- anytime::anydate(unique(selectedvariable0()$DATA_S2))
    updateSelectInput(inputId = "selectedvariable1", choices = choices) 
  })
  
  selectedvariable1 <- reactive({
    req(input$selectedvariable1)
    filter(selectedvariable0(), DATA_S2 == anytime::anydate(input$selectedvariable1))
  })
  observeEvent(selectedvariable1(), {
    choices <- unique(selectedvariable1()$PROJETO)
    updateSelectInput(inputId = "selectedvariable2", choices = choices)
  })
  
  selectedvariable2 <- reactive({
    req(input$selectedvariable2)
    filter(selectedvariable0(), PROJETO == input$selectedvariable2)
  })
  observeEvent(selectedvariable2(), {
    choices <- unique(selectedvariable2()$CD_TALHAO)
    updateSelectInput(inputId = "selectedvariable3", choices = choices)
  })
  
  selectedvariable3 <- reactive({
    req(input$selectedvariable3)
    filter(selectedvariable0(), CD_TALHAO == input$selectedvariable3)
  })
  observeEvent(selectedvariable3(), {
    choices <- unique(selectedvariable3()$ID_UNIQUE)
    updateSelectInput(inputId = "selectedvariable4", choices = choices)
  })
  selectedvariable4 <- reactive({
    req(input$selectedvariable4)
    filter(selectedvariable0(), ID_UNIQUE == input$selectedvariable4)
  })
  
  # Report creation
  output$download5 <- downloadHandler(
    filename = "report.html",
    content = function(file) {
      # identify the folders
      current.folder <- getwd()
      new.folder <- tempdir()
      # find the files that you want
      list.of.files <- list.files(current.folder, "report.Rmd$")
      # copy the files to the new folder
      file.copy(list.of.files, new.folder)
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
      rmarkdown::render(tempReport, output_file = file,
                        params = params,
                        envir = new.env(parent = globalenv())
      )
    }
  )
}
shinyApp(ui, server)
##

server <- function(input, output, session){
  
  
  selectedvariable0 <- reactive({
    filter(stands_ds, PEST == unique(stands_ds$PEST))
  })
  observeEvent(selectedvariable0(), {
    choices <- anytime::anydate(unique(selectedvariable0()$DATA_S2))
    updateSelectInput(inputId = "selectedvariable1", choices = choices) 
  })
  
  selectedvariable1 <- reactive({
    req(input$selectedvariable1)
    filter(selectedvariable0(), DATA_S2 == anytime::anydate(input$selectedvariable1))
  })
  observeEvent(selectedvariable1(), {
    choices <- unique(selectedvariable1()$PROJETO)
    updateSelectInput(inputId = "selectedvariable2", choices = choices)
  })
  
  selectedvariable2 <- reactive({
    req(input$selectedvariable2)
    filter(selectedvariable0(), PROJETO == input$selectedvariable2)
  })
  observeEvent(selectedvariable2(), {
    choices <- unique(selectedvariable2()$CD_TALHAO)
    updateSelectInput(inputId = "selectedvariable3", choices = choices)
  })
  
  selectedvariable3 <- reactive({
    req(input$selectedvariable3)
    filter(selectedvariable0(), CD_TALHAO == input$selectedvariable3)
  })
  observeEvent(selectedvariable3(), {
    choices <- unique(selectedvariable3()$ID_UNIQUE)
    updateSelectInput(inputId = "selectedvariable4", choices = choices)
  })
  selectedvariable4 <- reactive({
    req(input$selectedvariable4)
    filter(selectedvariable0(), ID_UNIQUE == input$selectedvariable4)
  })

  # Report creation
  output$download5 <- downloadHandler(
    filename = "report.html",
    content = function(file) {
      # identify the folders
      current.folder <- getwd()
      new.folder <- tempdir()
      # find the files that you want
      list.of.files <- list.files(current.folder, "report.Rmd$")
      # copy the files to the new folder
      file.copy(list.of.files, new.folder)
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
      rmarkdown::render(tempReport, output_file = file,
                        params = params,
                        envir = new.env(parent = globalenv())
      )
    }
  )
 }
shinyApp(ui, server)
##
#包
图书馆(shinythemes)
图书馆(lubridate)
图书馆(dplyr)
图书馆(随时)
需要(rmarkdown)
需要(knitr)
#获取AOI
下载文件(
"https://github.com/Leprechault/trash/raw/main/stands_example_v2.zip",

zip_路径我想你可能需要
runtime:shinny
谢谢,@akrun,但是在代码中需要放置
runtime:shinny
的确切位置?它应该在yaml中,即在ouptut行之后,你可以在downloadHandler中添加
runtime:shinny
,你可以存储变量
unique(selectedvariable1()$DATA\u S2)
params
中的
将其传递给RMarkdown文档。例如,请参阅此RMarkdown教程:谢谢,@akrun和@baroque问题已解决,但现在图像问题仍然存在,输出为:
中的错误:pandoc文档转换失败,错误99
---
title: <center> ![smille.jpg](smille.jpg) **Happy Dash** </center>
author: "by me"
date: " `r Sys.Date()` "
output: html_document
---
  
## Collected reactive data information
Total data: `r unique(selectedvariable1()$DATA_S2)`