R/snowflakes_server.R

Defines functions snowflakes_server

snowflakes_server <- function() {
  require(shiny)
  require(XML)
  
  sf <- file.path(system.file(package="LLP"),"snowflake.txt")
  xml <- XML::xmlInternalTreeParse(sf)
  r_list <- unlist(XML::xmlToList(xml))
  comment <- ""
  df <-
    data.frame(
      names = names(r_list),
      values = unlist(r_list),
      row.names = NULL,
      stringsAsFactors = F
    )
  shinyServer(function(input, output) {
    output$data_input <- renderUI({
      fluidRow(Map(function(x, y) {
        column(textInput(
          inputId = x,
          label = x,
          value = y,
          width = "50%"
        ),
        width = 5)
      },
      x = df$names,
      y = df$values))##fluidROw
      
    })#renderUI
    ############
    output$export <- downloadHandler(filename <-
                                       function() {
                                         "snowflake.txt"
                                       },
                                     content <- function(file) {
                                       temp <- tempfile()
                                       saveXML(LLP::make_snowflake(df, input$comment, input$user),
                                               temp,
                                               indent = T)
                                       file.copy(temp, file)
                                       # write.csv(mtcars,file)
                                     })
    #})
    
    ###########
  })
}
JARS3N/LiveLongAndProsper documentation built on June 21, 2020, 12:49 p.m.