Upload 2 files
Browse files
server.R
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
server <- function(input, output, session) {
|
2 |
+
# Reactive variable to store the original file content
|
3 |
+
originalFileContent <- reactiveVal()
|
4 |
+
|
5 |
+
# Observe file upload
|
6 |
+
observeEvent(input$file1, {
|
7 |
+
req(input$file1)
|
8 |
+
# Read the file content
|
9 |
+
fileContent <- readLines(input$file1$datapath)
|
10 |
+
# Store the original file content
|
11 |
+
originalFileContent(fileContent)
|
12 |
+
# Update Ace editor with file content
|
13 |
+
updateAceEditor(session, "code", value = paste(fileContent, collapse = "\n"), theme = "monokai")
|
14 |
+
})
|
15 |
+
|
16 |
+
# Function to generate YAML header
|
17 |
+
generate_yaml <- function() {
|
18 |
+
yaml_header <- c(
|
19 |
+
"---",
|
20 |
+
paste0("author: ", input$author),
|
21 |
+
paste0("date: ", if(input$date_type == 'custom') {input$date} else {'"`r Sys.Date()`"'}),
|
22 |
+
paste0("description: ", input$description),
|
23 |
+
"format:",
|
24 |
+
" html:",
|
25 |
+
paste0(" highlight-style: ", input$highlight_style),
|
26 |
+
paste0(" theme: ", input$theme),
|
27 |
+
paste0(" toc: ", ifelse(input$toc, "true", "false")),
|
28 |
+
" code-fold: true",
|
29 |
+
paste0(" file: ", tools::file_path_sans_ext(input$file1$name), ".", tools::file_ext(input$file1$name)),
|
30 |
+
paste0(" title: ", input$title),
|
31 |
+
paste0(' subtitle: "', input$subtitle, '"')
|
32 |
+
)
|
33 |
+
|
34 |
+
if (input$`toc-float`) {
|
35 |
+
yaml_header <- c(yaml_header,
|
36 |
+
" toc_float:",
|
37 |
+
" collapsed: true",
|
38 |
+
" smooth_scroll: true")
|
39 |
+
}
|
40 |
+
|
41 |
+
yaml_header <- c(yaml_header, "---")
|
42 |
+
|
43 |
+
return(yaml_header)
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
# Observe generate button
|
48 |
+
observeEvent(input$generate, {
|
49 |
+
# Generate YAML header
|
50 |
+
yaml_header <- generate_yaml()
|
51 |
+
# Combine YAML header and original file content
|
52 |
+
new_fileContent <- c(yaml_header, originalFileContent())
|
53 |
+
# Update Ace editor with new file content
|
54 |
+
updateAceEditor(session, "code", value = paste(new_fileContent, collapse = "\n"))
|
55 |
+
})
|
56 |
+
|
57 |
+
# Download handler
|
58 |
+
output$Download <- downloadHandler(
|
59 |
+
|
60 |
+
filename = function() {
|
61 |
+
paste(tools::file_path_sans_ext(input$file1$name), ".", tools::file_ext(input$file1$name), sep = "")
|
62 |
+
},
|
63 |
+
content = function(file) {
|
64 |
+
# Generate YAML header
|
65 |
+
yaml_header <- generate_yaml()
|
66 |
+
# Combine YAML header and original file content
|
67 |
+
new_fileContent <- c(yaml_header, originalFileContent())
|
68 |
+
# Write the new file content to the file
|
69 |
+
writeLines(new_fileContent, file)
|
70 |
+
}
|
71 |
+
)
|
72 |
+
}
|
ui.R
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
library(shiny)
|
3 |
+
library(shinyAce)
|
4 |
+
library(shinythemes)
|
5 |
+
ui <- fluidPage(
|
6 |
+
#shinythemes::themeSelector(),
|
7 |
+
tags$head(
|
8 |
+
tags$link(rel = "stylesheet", type = "text/css", href = "styles.css"),
|
9 |
+
tags$script(src = "script.js")
|
10 |
+
),
|
11 |
+
titlePanel("YAMLGen"),
|
12 |
+
|
13 |
+
sidebarLayout(
|
14 |
+
|
15 |
+
sidebarPanel(
|
16 |
+
img(src="portada.png", height=200, width=200),
|
17 |
+
textInput('title', 'Title'),
|
18 |
+
textInput('subtitle', 'Subtitle'),
|
19 |
+
textInput('author', 'Author'),
|
20 |
+
radioButtons('date_type', 'Date',
|
21 |
+
choices = c('Use system date' = '`r Sys.Date()`', 'Enter a date' = 'custom')),
|
22 |
+
conditionalPanel(
|
23 |
+
condition = "input.date_type == 'custom'",
|
24 |
+
dateInput('date', 'Date', value = Sys.Date())
|
25 |
+
),
|
26 |
+
textInput('description', 'Description'),
|
27 |
+
selectInput('highlight_style', 'Choose highlight style',
|
28 |
+
choices = c('default', 'github', 'tango', 'pygments', 'kate', 'monochrome', 'espresso', 'zenburn', 'haddock')),
|
29 |
+
selectInput('theme', 'Choose theme',
|
30 |
+
choices = c('cerulean', 'journal', 'flatly', 'darkly', 'readable', 'spacelab', 'united', 'cosmo', 'lumen', 'paper', 'sandstone', 'simplex', 'yeti')),
|
31 |
+
checkboxInput('toc', 'Table of Contents', value = FALSE),
|
32 |
+
checkboxInput('code-fold', 'Code fold', value = FALSE),
|
33 |
+
checkboxInput('toc-float', 'Table of Contents Float', value = FALSE),
|
34 |
+
conditionalPanel(
|
35 |
+
condition = "input['toc-float'] == true",
|
36 |
+
checkboxInput('collapsed', 'Collapsed', value = TRUE),
|
37 |
+
checkboxInput('smooth_scroll', 'Smooth Scroll', value = TRUE)
|
38 |
+
),
|
39 |
+
|
40 |
+
helpText(),
|
41 |
+
fileInput('file1', 'Choose qmd or Markdown File',
|
42 |
+
accept=c('text/qmd', 'text/markdown',
|
43 |
+
'text/comma-separated-values,text/plain',
|
44 |
+
'.csv', '.qmd', '.md')), # End of file input
|
45 |
+
downloadButton('Download', 'Download Document'),
|
46 |
+
actionButton('generate', 'Generate YAML Header'),
|
47 |
+
tags$a(href = "https://github.com/pablovanegas/runr", target = "_blank", class = "btn btn-default shiny-bound-input", "Ver C贸digo Fuente"),
|
48 |
+
tags$a(href = "https://huggingface.co/spaces/pajuan/bbbb", target = "_blank", class = "btn btn-default shiny-bound-input", "Markdown generator")
|
49 |
+
), # End of sidebar panel
|
50 |
+
|
51 |
+
mainPanel(
|
52 |
+
h2("This is an app to help you create YALM headers for your documents"),
|
53 |
+
# User Guide #generate the .col-sm-8 class
|
54 |
+
tags$div(
|
55 |
+
h2("User Guide", class = 'guide-title'),
|
56 |
+
tags$ol(
|
57 |
+
tags$li("If you're going to update your document make sure to delete this before you begin."),
|
58 |
+
tags$li("Custom your header: Enter your own title, author, and description in the respective text input fields on the sidebar panel."),
|
59 |
+
tags$li("Choose the Date: You have the option to use the system date or enter a custom date. Select your preference using the 'Date' radio buttons."),
|
60 |
+
tags$li("Select Highlight Style and Theme: Choose your preferred highlight style and theme from the dropdown menus."),
|
61 |
+
tags$li("Table of Contents and Code Fold: If you want a table of contents or code fold in your document, check the respective boxes."),
|
62 |
+
tags$li("Upload Your File: Choose the QMD or Markdown file you want to work with using the 'Choose qmd or Markdown File' button."),
|
63 |
+
tags$li("Download Your Document: Once you're done, click the 'Download Document' button to get your document.")
|
64 |
+
),
|
65 |
+
p("Remember, make sure to decide on the parameters before inserting the archive or you can generate the header without the file and click on generate YALM"),
|
66 |
+
), # End of User Guide
|
67 |
+
|
68 |
+
|
69 |
+
img(src = "guia.png", height = 300, width = 1000, align = "center"),
|
70 |
+
br(),
|
71 |
+
p(" "),
|
72 |
+
p("Your YALM : "),
|
73 |
+
tableOutput("contents"),
|
74 |
+
|
75 |
+
fluidRow(
|
76 |
+
column(12, wellPanel(
|
77 |
+
aceEditor('code', mode = 'r', theme = 'chaos', fontSize = 12, height = '400px')
|
78 |
+
))
|
79 |
+
) # End of fluid row
|
80 |
+
|
81 |
+
) #End Main Panel
|
82 |
+
|
83 |
+
) # End Slider Layout
|
84 |
+
|
85 |
+
) # End of fluid page
|