Coder Social home page Coder Social logo

notemd's Introduction

noteMD

Print text from shiny ui (support markdown syntax) to pdf or word report! This is a live demo shiny app using noteMD R package: https://appforiarteam.shinyapps.io/noteMD_shiny_demo/ Code of this live demo shiny app is here (welcome to download): https://github.com/jienagu/noteMD_shiny_app

Acknowledgement

Beef Cattle Institute at Kansas State University: https://ksubci.org/

Special thanks to Yihui Xie (from RStudio.LLC), Dr. Brad White and Dr. David Amrine

Install

install.packages("noteMD")

Install from GitHub :
devtools::install_github("jienagu/noteMD")

Basically, this is how to use noteMD to insert a text box in your shiny ui (support markdown syntax) to pdf or word report!

  • Step 1: create a textarea in shiny ui: tags$textarea( "Please using any **markdown** syntax!", id = 'markdowninput', rows = 3, style = 'width:100%;'), here we know the id of this tag is markdowninput (you can name whatever you want)

  • Step 2: if you want to have a preview in shiny app like the demo, use output$htmlmarkdown = reactive({note_in_html(input$markdowninput) }) , then htmlOutput('htmlmarkdown') in shiny ui

  • Step 3: if your report is in pdf, put note_in_md_pdf(input$markdowninput) in an R chunk (whereever you want to insert the text); if your report is in word, put note_in_md_word(input$markdowninput) in an R chunk!

Future improvements:

  • Support math formula writting

Enjoy!

notemd's People

Contributors

jienagu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

notemd's Issues

Error when using noteMD to insert a text box in shiny ui to pdf or word report.

I have a basic shiny app which is a total copy paste of the app you can find here and its code. While the app seems to work fine. When I try to run it in rstudio the reports are not downlaoded. Instead I get : Warning: Error in abs_path: The file 'summary_report_word.Rmd' does not exist..

library(shiny)
# devtools::install_github("jienagu/noteMD")
library(noteMD)
library(knitr)  
library(rmarkdown)
# Define UI for application that draws a histogram
ui <- fluidPage(
  
  # Application title
  titlePanel("Old Faithful Geyser Data"),
  
  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(
      downloadButton('describe_download',"Download Report",class="butt" ),br(),
      tags$head(tags$style(".butt{background-color:#230682;} .butt{color: #e6ebef;}")),
      radioButtons('format', 'Document format', c('PDF', 'Word'),
                   inline = TRUE)
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      fluidRow(
        column(12,
               helpText("Note: Any comments made in the box will be printed if you download the summary report.") ),
        column(12,
               tags$textarea(
                 "Please using any **markdown** syntax!",
                 id    = 'markdowninput',
                 rows  = 3,
                 style = 'width:100%;')) ),
      helpText("Preview:"),
      htmlOutput('htmlmarkdown')
      
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  
  
  output$htmlmarkdown = reactive({
    note_in_html(input$markdowninput)
  })
  
  output$describe_download = downloadHandler(
    filename<- function(){
      paste("Summary",Sys.Date(),switch(
        input$format, PDF = '.pdf', Word = '.docx'
      ),sep = "")
    },
    
    content = function(file) {
      if (input$format=="PDF"){
        #### Progressing indicator
        withProgress(message = 'Download in progress',
                     detail = 'This may take a while...', value = 0, {
                       for (i in 1:15) {
                         incProgress(1/15)
                         Sys.sleep(0.01)
                       }
                       
                       ## End of progression
                       src <- normalizePath('summary_report.Rmd')
                       
                       # temporarily switch to the temp dir, in case you do not have write
                       # permission to the current working directory
                       owd <- setwd(tempdir())
                       on.exit(setwd(owd))
                       file.copy(src, 'summary_report.Rmd', overwrite = TRUE)
                       
                       library(rmarkdown)
                       out <- render('summary_report.Rmd', pdf_document())
                       file.rename(out, file)
                       
                     })
        ### below is the end of pdf content
      }else{
        withProgress(message = 'Download in progress',
                     detail = 'This may take a while...', value = 0, {
                       for (i in 1:15) {
                         incProgress(1/15)
                         Sys.sleep(0.01)
                       }
                       
                       ## End of progression
                       src <- normalizePath('summary_report_word.Rmd')
                       
                       # temporarily switch to the temp dir, in case you do not have write
                       # permission to the current working directory
                       owd <- setwd(tempdir())
                       on.exit(setwd(owd))
                       file.copy(src, 'summary_report_word.Rmd', overwrite = TRUE)
                       
                       library(rmarkdown)
                       out <- render('summary_report_word.Rmd', word_document())
                       file.rename(out, file)
                     })
      }
      
    })
  
  
}

# Run the application 
shinyApp(ui = ui, server = server)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.