I am trying to build my first Shiny app.
I have a user defined function which takes generates encryption keys. I'd like to make it in to a Shiny app.
I had a go as below. The first bit of the UI works in that it asks for text input for the users name (this should be used to label the output files) - and I managed to get an action button which the user could then click to in theory run the code to make the encryption keys.
library(shiny)
# Define UI for ODK Encryption app ----
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Make ODK Encryption Keys"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textInput("name",
"Enter your name:"),
actionButton(inputId = "input_action", label = "Generate Keys")
),
mainPanel(
)
)
)
I feel that there ?should be something in mainPanel to give a link for the outputted key files or alternatively they could just automatically get downloaded?
Then within the server section I 1) Take the sys-date-time as a seed 2) Take the name (as inputted above) and link that to the sys-date to make a file name for the eventual keys 3) Then I define my function (create.key.pair) - This takes the sys-date-time (set in 1 above) and uses that and openSSL to generate a public and private key. It labels these files using the name inputted in point 2 (which should take the input from the sidebar section of the UI in the shiny app)
#Make the Key
server <- function(input, output) {
observeEvent(input$button, {
key_seed <- round(as.numeric(Sys.time()),0)
key_name <- paste(name,Sys.Date(),sep="_")
create.key.pair<-function(keynumber)
{
folder<-paste("ODK.KEY",key_name,sep=".") #make a folder name
system(paste("mkdir",folder,sep=" ")) #create the folder
name.private.key<-paste("ODK.PRIVATE.KEY.",key_name,".pem",sep = "") #make a name for the keys
name.public.key<-paste("ODK.PUBLIC.KEY.",key_name,".pem",sep = "")
keygen.private<-paste("openssl genrsa -out ",folder,"/",name.private.key," 2048",sep="") #create the system call
system(command = keygen.private) #create the private key
keygen.public<-paste("openssl rsa -in ",folder,"/",name.private.key," -inform PEM -out ",folder,"/",name.public.key," -outform PEM -pubout",sep="")
system(command = keygen.public) #create the private key
}
create.key.pair(key_seed)
})
}
shinyApp(ui, server)
I need some guidance on whether A) I need to add something within mainPanel to show/download the outputted files B) The code within the server section should work
I can't currently tell if my error is in A or B just that it doesnt generate keys (whereas my R script version of this works just fine)
First time using Shiny so any help gratefully accepted.
key_name
is not specified as parameter – Thomas