-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
99 lines (72 loc) · 2.83 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
library(tidyverse)
library(shiny)
library(pryr)
# Load functions
source("functions.R")
# Load inputdata
load("./data/inputData.RData", envir=.GlobalEnv)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Translate text to DNA"),
# Sidebar with a text input and option to translate to text or DNA.
sidebarLayout(
sidebarPanel(
width = 6,
# Text input area
textAreaInput(inputId = "textIn", label = "Input Text", width = "100%", placeholder = "Enter your text"),
# Translate to button
radioButtons(inputId = "choice", label = "Translate into", choices = c("DNA" = "dna", "Plain text" = "text")),
# Submit button
actionButton(inputId = "button", label = "Translate"),
# Extra info
tags$div(class="header", checked=NA,
tags$p(""),
HTML("<br><h4> Designed and coded by <a href=https://sanderwuyts.com>Sander Wuyts</a></h4>" ),
HTML("<br>
Based on <a href=https://www.nature.com/articles/nature11875>Goldman et al (2013)</a> and <a href=https://github.com/swuyts/textToDNA>Allanino</a>."),
HTML("Thank you to <a href=http://adrem.uantwerpen.be/>ADReM</a> for hosting this web app.")
)
),
# Show a plot of the generated distribution
mainPanel(
width = 6,
verbatimTextOutput(outputId = "out")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
inputText <- eventReactive(input$button, {
validate(
# Make sure that text is not empty
need(input$textIn != "", "Please provide an input"),
# Make sure that input is no longer than 500 characters for text to DNA and 1000 from DNA to text
if_else(input$choice == "dna",
need(nchar(input$textIn) <= 500, "Please do not enter more than 500 characters"),
need(nchar(input$textIn) <= 2500, "Please do not enter more than 1000 DNA letters")),
# If going from DNA to text, validate whether only DNA is enterd
if(input$choice == "text"){
# Trim whitespaces in DNA input and
# Check if there are other characters than ACTG
need(str_detect( input$textIn %>% str_remove_all("[ \n]"), "^[ATCG]*$"), "Please enter DNA only")}
)
as.character(input$textIn)
})
# Main output
output$out <- renderText({
if (isolate(input$choice == "dna")) {
# From text to DNA
S0_to_S1(inputText()) %>%
S1_to_S5()
} else {
# From DNA to text
inputText() %>%
str_remove_all("[ \n]") %>%
S5_to_S1() %>%
S1_to_S0()
}
})
}
# Run the application
shinyApp(ui = ui, server = server)