diff --git a/.Rbuildignore b/.Rbuildignore index 8445c50..8b46705 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,12 +1,10 @@ -^.*\.Rproj$ -^\.Rproj\.user$ -^\.travis\.yml$ -^appveyor\.yml$ -^_pkgdown\.yml$ -^docs$ -^pkgdown$ -^LICENSE\.md$ -^Rprofile.site$ -^Dockerfile$ -^\.lintr$ -^\.github$ +^.*\.Rproj$ +^\.Rproj\.user$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ +^LICENSE\.md$ +^Rprofile.site$ +^Dockerfile$ +^\.lintr$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore deleted file mode 100644 index 2d19fc7..0000000 --- a/.github/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.html diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..a41ec97 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,54 @@ +name: Publish Docker image +on: + release: + types: [published] + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + push_to_registries: + name: Push Docker image to docker hub + runs-on: ubuntu-latest + env: + IMAGE_NAME: ${{ github.repository }} + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: R setup + uses: r-lib/actions/setup-r@v2.6.5 + - name: Build package (tarball) + run: R CMD build . + - name: Lint Dockerfile + uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: "Dockerfile" + - name: Prepare tags + id: docker_meta + uses: docker/metadata-action@v5.0.0 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.0.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Push to Docker Hub + uses: docker/build-push-action@v5.0.0 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index 6e7f26b..c525888 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ figure inst/shinyApps/app1/*.md inst/*.md docs/ +*.tar.gz diff --git a/DESCRIPTION b/DESCRIPTION index 5e487b7..a710ba6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ Remotes: License: GPL-3 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 URL: http://github.com/Rapporteket/rapRegTemplate BugReports: http://github.com/Rapporteket/rapRegTemplate/issues Suggests: diff --git a/Dockerfile b/Dockerfile index eaeb889..1d72ab8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,17 @@ -FROM rocker/r-base +FROM rapporteket/base-r:4.2.1 -LABEL maintainer "Are Edvardsen " -LABEL no.mongr.cd.enable="true" +LABEL maintainer "Arnfinn Hykkerud Steindal " -# system libraries of general use -RUN apt-get update && apt-get install -y \ - sudo \ - pandoc \ - pandoc-citeproc \ - libcurl4-gnutls-dev \ - libcairo2-dev \ - libxt-dev \ - libxml2-dev \ - default-jdk \ - libssl-dev \ - libmariadbclient-dev +LABEL no.rapporteket.cd.enable="true" -# basic R functionality -RUN R -e "install.packages(c('remotes'), repos='https://cloud.r-project.org/')" +WORKDIR /app/R -# install rapRegTemplate app -RUN R -e "remotes::install_github('Rapporteket/rapRegTemplate')" +# hadolint ignore=DL3010 +COPY *.tar.gz . -# copy the app to the image -RUN mkdir /root/rapRegTemplate -COPY inst/shinyApps/app1 /root/rapRegTemplate - -COPY Rprofile.site /usr/lib/R/etc/ +RUN R -e "remotes::install_local(list.files(pattern = \"*.tar.gz\"))" \ + && rm ./*.tar.gz EXPOSE 3838 -CMD ["R", "-e", "shiny::runApp('/root/rapRegTemplate')"] +CMD ["R", "-e", "options(shiny.port = 3838,shiny.host = \"0.0.0.0\"); rapRegTemplate::run_app()"] diff --git a/NAMESPACE b/NAMESPACE index bb9294d..3e91da2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,10 @@ # Generated by roxygen2: do not edit by hand +export("%>%") +export(app_server) +export(app_ui) export(getFakeRegData) export(getRegData) export(makeHist) +export(run_app) +importFrom(magrittr,"%>%") diff --git a/inst/shinyApps/app1/server.R b/R/app_server.R similarity index 86% rename from inst/shinyApps/app1/server.R rename to R/app_server.R index c9f9020..25f6ef3 100644 --- a/inst/shinyApps/app1/server.R +++ b/R/app_server.R @@ -1,297 +1,302 @@ -library(shiny) -library(magrittr) -library(rapRegTemplate) - -server <- function(input, output, session) { - - # Last inn data - # regData <- getFakeRegData() - - # Brukerinformasjon i menylinja (navbar) - output$appUserName <- - shiny::renderText( - paste(rapbase::getUserFullName(session), - rapbase::getUserRole(session), sep = ", ")) - output$appOrgName <- shiny::renderText(rapbase::getUserReshId(session)) - userInfo <- - rapbase::howWeDealWithPersonalData(session, callerPkg = "rapRegTemplate") - shiny::observeEvent(input$userInfo, { - shinyalert("Dette vet Rapporteket om deg:", userInfo, - type = "", imageUrl = "rap/logo.svg", - closeOnEsc = TRUE, closeOnClickOutside = TRUE, - html = TRUE, confirmButtonText = rapbase::noOptOutOk()) - }) - - # Veiledning - output$veiledning <- renderUI({ - rapbase::renderRmd( - system.file("veiledning.Rmd", package = "rapRegTemplate"), - outputType = "html_fragment" - ) - }) - - - # Figur og tabell - ## Figur - # output$distPlot <- renderPlot({ - # makeHist(df = regData, var = input$var, bins = input$bins) - # }) - - ## Tabell - #output$distTable <- renderTable({ - # makeHist(df = regData, var = input$var, bins = input$bins, - # makeTable = TRUE) - #}) - - - # Samlerapport - ## vis - output$samlerapport <- shiny::renderUI({ - rapbase::renderRmd( - system.file("samlerapport.Rmd", package = "rapRegTemplate"), - outputType = "html_fragment", - params = list(type = "html", - var = input$varS, - bins = input$binsS) - ) - }) - - ## last ned - output$downloadSamlerapport <- shiny::downloadHandler( - filename = function() { - basename(tempfile(pattern = "rapRegTemplateSamlerapport", - fileext = paste0(".", input$formatS))) - }, - content = function(file) { - srcFile <- - normalizePath(system.file("samlerapport.Rmd", package = "rapRegTemplate")) - fn <- rapbase::renderRmd(srcFile, outputType = input$formatS, - params = list(type = input$formatS, - var = input$varS, - bins = input$binsS)) - file.rename(fn, file) - } - ) - - - # Abonnement - ## rekative verdier for å holde rede på endringer som skjer mens - ## applikasjonen kjører - subscription <- shiny::reactiveValues( - tab = rapbase::makeAutoReportTab(session, type = "subscription")) - - ## lag tabell over gjeldende status for abonnement - output$activeSubscriptions <- DT::renderDataTable( - subscription$tab, server = FALSE, escape = FALSE, selection = "none", - options = list(dom = "tp", ordning = FALSE, - columnDefs = list(list(visible = FALSE, targets = 6))), - rownames = FALSE - ) - - ## lag side som viser status for abonnement, også når det ikke finnes noen - output$subscriptionContent <- shiny::renderUI({ - userFullName <- rapbase::getUserFullName(session) - if (length(subscription$tab) == 0) { - shiny::p(paste("Ingen aktive abonnement for", userFullName)) - } else { - shiny::tagList( - shiny::p(paste0("Aktive abonnement som sendes per epost til ", - userFullName, ":")), - DT::dataTableOutput("activeSubscriptions") - ) - } - }) - - ## nye abonnement - shiny::observeEvent(input$subscribe, { - package <- "rapRegTemplate" - type <- "subscription" - owner <- rapbase::getUserName(session) - interval <- strsplit(input$subscriptionFreq, "-")[[1]][2] - intervalName <- strsplit(input$subscriptionFreq, "-")[[1]][1] - runDayOfYear <- rapbase::makeRunDayOfYearSequence( - interval = interval) - - email <- rapbase::getUserEmail(session) - organization <- rapbase::getUserReshId(session) - - if (input$subscriptionRep == "Samlerapport1") { - synopsis <- "Automatisk samlerapport1" - fun <- "samlerapport1Fun" - paramNames <- c("p1", "p2") - paramValues <- c("Alder", 1) - - } - if (input$subscriptionRep == "Samlerapport2") { - synopsis <- "Automatisk samlerapport2" - fun <- "samlerapport2Fun" - paramNames <- c("p1", "p2") - paramValues <- c("BMI", 2) - } - rapbase::createAutoReport(synopsis = synopsis, package = package, - type = type, fun = fun, paramNames = paramNames, - paramValues = paramValues, owner = owner, - email = email, organization = organization, - runDayOfYear = runDayOfYear, - interval = interval, intervalName = intervalName) - subscription$tab <- - rapbase::makeAutoReportTab(session, type = "subscription") - }) - - - # Utsending - ## reaktive verdier for å holde rede på endringer som skjer mens - ## applikasjonen kjører - dispatchment <- shiny::reactiveValues( - tab = rapbase::makeAutoReportTab(session = session, type = "dispatchment"), - report = "Automatisk samlerapport1", - freq = "Månedlig-month", - email = vector() - ) - - ## observér og foreta endringer mens applikasjonen kjører - shiny::observeEvent(input$addEmail, { - dispatchment$email <- c(dispatchment$email, input$email) - }) - shiny::observeEvent(input$delEmail, { - dispatchment$email <- - dispatchment$email[!dispatchment$email == input$email] - }) - shiny::observeEvent(input$dispatch, { - package <- "rapRegTemplate" - type <- "dispatchment" - owner <- rapbase::getUserName(session) - ownerName <- rapbase::getUserFullName(session) - interval <- strsplit(input$dispatchmentFreq, "-")[[1]][2] - intervalName <- strsplit(input$dispatchmentFreq, "-")[[1]][1] - runDayOfYear <- rapbase::makeRunDayOfYearSequence( - interval = interval) - - email <- dispatchment$email - organization <- rapbase::getUserReshId(session) - - if (input$dispatchmentRep == "Automatisk samlerapport1") { - synopsis <- "Automatisk samlerapport1" - fun <- "samlerapport1Fun" - paramNames <- c("p1", "p2") - paramValues <- c("Alder", 1) - - } - if (input$dispatchmentRep == "Automatisk samlerapport2") { - synopsis <- "Automatisk samlerapport2" - fun <- "samlerapport2Fun" - paramNames <- c("p1", "p2") - paramValues <- c("BMI", 2) - } - rapbase::createAutoReport(synopsis = synopsis, package = package, - type = type, fun = fun, paramNames = paramNames, - paramValues = paramValues, owner = owner, - ownerName = ownerName, - email = email, organization = organization, - runDayOfYear = runDayOfYear, - interval = interval, intervalName = intervalName) - dispatchment$tab <- - rapbase::makeAutoReportTab(session, type = "dispatchment") - dispatchment$email <- vector() - }) - - ## ui: velg rapport - output$report <- shiny::renderUI({ - shiny::selectInput( - "dispatchmentRep", "Rapport:", - c("Automatisk samlerapport1", "Automatisk samlerapport2"), - selected = dispatchment$report) - }) - - ## ui: velg frekvens - output$freq <- shiny::renderUI({ - shiny::selectInput( - "dispatchmentFreq", "Frekvens:", - list(Årlig = "Årlig-year", - Kvartalsvis = "Kvartalsvis-quarter", - Månedlig = "Månedlig-month", - Ukentlig = "Ukentlig-week", - Daglig = "Daglig-DSTday"), - selected = dispatchment$freq) - }) - - ## ui: legg til gyldig- og slett epost - output$editEmail <- shiny::renderUI({ - if (!grepl("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$", - input$email)) { - shiny::tags$p("Angi mottaker over") - } else { - if (input$email %in% dispatchment$email) { - shiny::actionButton("delEmail", "Slett epostmottaker", - icon = shiny::icon("trash")) - } else { - shiny::actionButton("addEmail", "Legg til epostmottaker", - icon = shiny::icon("pencil")) - } - } - }) - - ## ui: vis valgte mottakere - output$recipients <- shiny::renderText(paste(dispatchment$email, - sep = "
")) - - ## ui: lag ny utsending - output$makeDispatchment <- shiny::renderUI({ - if (length(dispatchment$email) == 0) { - NULL - } else { - shiny::actionButton("dispatch", "Lag utsending", - icon = shiny::icon("save")) - } - }) - - ## lag tabell over gjeldende status for utsending - output$activeDispatchments <- DT::renderDataTable( - dispatchment$tab, server = FALSE, escape = FALSE, selection = "none", - options = list(dom = "tp", ordering = FALSE), rownames = FALSE - ) - - - ## ui: lag side som viser status for utsending, også når det ikke finnes noen - output$dispatchmentContent <- shiny::renderUI({ - if (length(dispatchment$tab) == 0) { - shiny::p("Det finnes ingen utendinger") - } else { - shiny::tagList( - shiny::p("Aktive utsendinger:"), - DT::dataTableOutput("activeDispatchments") - ) - } - }) - - # Rediger eksisterende auto rapport (alle typer) - shiny::observeEvent(input$edit_button, { - repId <- strsplit(input$edit_button, "_")[[1]][2] - rep <- rapbase::readAutoReportData()[[repId]] - if (rep$type == "subscription") { - - } - if (rep$type == "dispatchment") { - dispatchment$freq <- paste0(rep$intervalName, "-", rep$interval) - dispatchment$email <- rep$email - rapbase::deleteAutoReport(repId) - dispatchment$tab <- - rapbase::makeAutoReportTab(session, type = "dispatchment") - dispatchment$report <- rep$synopsis - } - if (rep$type == "bulletin") { - - } - }) - - # Slett eksisterende auto rapport (alle typer) - shiny::observeEvent(input$del_button, { - repId <- strsplit(input$del_button, "_")[[1]][2] - rapbase::deleteAutoReport(repId) - subscription$tab <- - rapbase::makeAutoReportTab(session, type = "subscription") - dispatchment$tab <- - rapbase::makeAutoReportTab(session, type = "dispatchment") - }) - -} +#' Server logic for the rapRegTemplate app +#' +#' @param input shiny input object +#' @param output shiny output object +#' @param session shiny session object +#' +#' @return A shiny app server object +#' @export + +app_server <- function(input, output, session) { + + # Last inn data + regData <- getFakeRegData() + + # Brukerinformasjon i menylinja (navbar) + output$appUserName <- + shiny::renderText( + paste(rapbase::getUserFullName(session), + rapbase::getUserRole(session), sep = ", ")) + output$appOrgName <- shiny::renderText(rapbase::getUserReshId(session)) + userInfo <- + rapbase::howWeDealWithPersonalData(session, callerPkg = "rapRegTemplate") + shiny::observeEvent(input$userInfo, { + shinyalert::shinyalert("Dette vet Rapporteket om deg:", userInfo, + type = "", imageUrl = "rap/logo.svg", + closeOnEsc = TRUE, closeOnClickOutside = TRUE, + html = TRUE, confirmButtonText = rapbase::noOptOutOk()) + }) + + # Veiledning + output$veiledning <- shiny::renderUI({ + rapbase::renderRmd( + system.file("veiledning.Rmd", package = "rapRegTemplate"), + outputType = "html_fragment" + ) + }) + + + # Figur og tabell + # Figur + output$distPlot <- renderPlot({ + makeHist(df = regData, var = input$var, bins = input$bins) + }) + + # Tabell + output$distTable <- renderTable({ + makeHist(df = regData, var = input$var, bins = input$bins, + makeTable = TRUE) + }) + + + # Samlerapport + ## vis + output$samlerapport <- shiny::renderUI({ + rapbase::renderRmd( + system.file("samlerapport.Rmd", package = "rapRegTemplate"), + outputType = "html_fragment", + params = list(type = "html", + var = input$varS, + bins = input$binsS) + ) + }) + + ## last ned + output$downloadSamlerapport <- shiny::downloadHandler( + filename = function() { + basename(tempfile(pattern = "rapRegTemplateSamlerapport", + fileext = paste0(".", input$formatS))) + }, + content = function(file) { + srcFile <- + normalizePath(system.file("samlerapport.Rmd", package = "rapRegTemplate")) + fn <- rapbase::renderRmd(srcFile, outputType = input$formatS, + params = list(type = input$formatS, + var = input$varS, + bins = input$binsS)) + file.rename(fn, file) + } + ) + + + # Abonnement + ## rekative verdier for aa holde rede paa endringer som skjer mens + ## applikasjonen kjorer + subscription <- shiny::reactiveValues( + tab = rapbase::makeAutoReportTab(session, type = "subscription")) + + ## lag tabell over gjeldende status for abonnement + output$activeSubscriptions <- DT::renderDataTable( + subscription$tab, server = FALSE, escape = FALSE, selection = "none", + options = list(dom = "tp", ordning = FALSE, + columnDefs = list(list(visible = FALSE, targets = 6))), + rownames = FALSE + ) + + ## lag side som viser status for abonnement, ogsaa naar det ikke finnes noen + output$subscriptionContent <- shiny::renderUI({ + userFullName <- rapbase::getUserFullName(session) + if (length(subscription$tab) == 0) { + shiny::p(paste("Ingen aktive abonnement for", userFullName)) + } else { + shiny::tagList( + shiny::p(paste0("Aktive abonnement som sendes per epost til ", + userFullName, ":")), + DT::dataTableOutput("activeSubscriptions") + ) + } + }) + + ## nye abonnement + shiny::observeEvent(input$subscribe, { + package <- "rapRegTemplate" + type <- "subscription" + owner <- rapbase::getUserName(session) + interval <- strsplit(input$subscriptionFreq, "-")[[1]][2] + intervalName <- strsplit(input$subscriptionFreq, "-")[[1]][1] + runDayOfYear <- rapbase::makeRunDayOfYearSequence( + interval = interval) + + email <- rapbase::getUserEmail(session) + organization <- rapbase::getUserReshId(session) + + if (input$subscriptionRep == "Samlerapport1") { + synopsis <- "Automatisk samlerapport1" + fun <- "samlerapport1Fun" + paramNames <- c("p1", "p2") + paramValues <- c("Alder", 1) + + } + if (input$subscriptionRep == "Samlerapport2") { + synopsis <- "Automatisk samlerapport2" + fun <- "samlerapport2Fun" + paramNames <- c("p1", "p2") + paramValues <- c("BMI", 2) + } + rapbase::createAutoReport(synopsis = synopsis, package = package, + type = type, fun = fun, paramNames = paramNames, + paramValues = paramValues, owner = owner, + email = email, organization = organization, + runDayOfYear = runDayOfYear, + interval = interval, intervalName = intervalName) + subscription$tab <- + rapbase::makeAutoReportTab(session, type = "subscription") + }) + + + # Utsending + ## reaktive verdier for aa holde rede paa endringer som skjer mens + ## applikasjonen kjorer + dispatchment <- shiny::reactiveValues( + tab = rapbase::makeAutoReportTab(session = session, type = "dispatchment"), + report = "Automatisk samlerapport1", + freq = "M\u00E5nedlig-month", + email = vector() + ) + + ## observer og foreta endringer mens applikasjonen kjorer + shiny::observeEvent(input$addEmail, { + dispatchment$email <- c(dispatchment$email, input$email) + }) + shiny::observeEvent(input$delEmail, { + dispatchment$email <- + dispatchment$email[!dispatchment$email == input$email] + }) + shiny::observeEvent(input$dispatch, { + package <- "rapRegTemplate" + type <- "dispatchment" + owner <- rapbase::getUserName(session) + ownerName <- rapbase::getUserFullName(session) + interval <- strsplit(input$dispatchmentFreq, "-")[[1]][2] + intervalName <- strsplit(input$dispatchmentFreq, "-")[[1]][1] + runDayOfYear <- rapbase::makeRunDayOfYearSequence( + interval = interval) + + email <- dispatchment$email + organization <- rapbase::getUserReshId(session) + + if (input$dispatchmentRep == "Automatisk samlerapport1") { + synopsis <- "Automatisk samlerapport1" + fun <- "samlerapport1Fun" + paramNames <- c("p1", "p2") + paramValues <- c("Alder", 1) + + } + if (input$dispatchmentRep == "Automatisk samlerapport2") { + synopsis <- "Automatisk samlerapport2" + fun <- "samlerapport2Fun" + paramNames <- c("p1", "p2") + paramValues <- c("BMI", 2) + } + rapbase::createAutoReport(synopsis = synopsis, package = package, + type = type, fun = fun, paramNames = paramNames, + paramValues = paramValues, owner = owner, + ownerName = ownerName, + email = email, organization = organization, + runDayOfYear = runDayOfYear, + interval = interval, intervalName = intervalName) + dispatchment$tab <- + rapbase::makeAutoReportTab(session, type = "dispatchment") + dispatchment$email <- vector() + }) + + ## ui: velg rapport + output$report <- shiny::renderUI({ + shiny::selectInput( + "dispatchmentRep", "Rapport:", + c("Automatisk samlerapport1", "Automatisk samlerapport2"), + selected = dispatchment$report) + }) + + ## ui: velg frekvens + output$freq <- shiny::renderUI({ + shiny::selectInput( + "dispatchmentFreq", "Frekvens:", + list("\u00C5rlig" = "\u00C5rlig-year", + Kvartalsvis = "Kvartalsvis-quarter", + Maanedlig = "M\u00E5nedlig-month", + Ukentlig = "Ukentlig-week", + Daglig = "Daglig-DSTday"), + selected = dispatchment$freq) + }) + + ## ui: legg til gyldig- og slett epost + output$editEmail <- shiny::renderUI({ + if (!grepl("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$", + input$email)) { + shiny::tags$p("Angi mottaker over") + } else { + if (input$email %in% dispatchment$email) { + shiny::actionButton("delEmail", "Slett epostmottaker", + icon = shiny::icon("trash")) + } else { + shiny::actionButton("addEmail", "Legg til epostmottaker", + icon = shiny::icon("pencil")) + } + } + }) + + ## ui: vis valgte mottakere + output$recipients <- shiny::renderText(paste(dispatchment$email, + sep = "
")) + + ## ui: lag ny utsending + output$makeDispatchment <- shiny::renderUI({ + if (length(dispatchment$email) == 0) { + NULL + } else { + shiny::actionButton("dispatch", "Lag utsending", + icon = shiny::icon("save")) + } + }) + + ## lag tabell over gjeldende status for utsending + output$activeDispatchments <- DT::renderDataTable( + dispatchment$tab, server = FALSE, escape = FALSE, selection = "none", + options = list(dom = "tp", ordering = FALSE), rownames = FALSE + ) + + + ## ui: lag side som viser status for utsending, ogsaa naar det ikke finnes noen + output$dispatchmentContent <- shiny::renderUI({ + if (length(dispatchment$tab) == 0) { + shiny::p("Det finnes ingen utendinger") + } else { + shiny::tagList( + shiny::p("Aktive utsendinger:"), + DT::dataTableOutput("activeDispatchments") + ) + } + }) + + # Rediger eksisterende auto rapport (alle typer) + shiny::observeEvent(input$edit_button, { + repId <- strsplit(input$edit_button, "_")[[1]][2] + rep <- rapbase::readAutoReportData()[[repId]] + if (rep$type == "subscription") { + + } + if (rep$type == "dispatchment") { + dispatchment$freq <- paste0(rep$intervalName, "-", rep$interval) + dispatchment$email <- rep$email + rapbase::deleteAutoReport(repId) + dispatchment$tab <- + rapbase::makeAutoReportTab(session, type = "dispatchment") + dispatchment$report <- rep$synopsis + } + if (rep$type == "bulletin") { + + } + }) + + # Slett eksisterende auto rapport (alle typer) + shiny::observeEvent(input$del_button, { + repId <- strsplit(input$del_button, "_")[[1]][2] + rapbase::deleteAutoReport(repId) + subscription$tab <- + rapbase::makeAutoReportTab(session, type = "subscription") + dispatchment$tab <- + rapbase::makeAutoReportTab(session, type = "dispatchment") + }) + +} diff --git a/R/app_ui.R b/R/app_ui.R new file mode 100644 index 0000000..f01d661 --- /dev/null +++ b/R/app_ui.R @@ -0,0 +1,122 @@ +#' Client (ui) for the rapRegTemplate app +#' +#' @return An shiny app ui object +#' @export + +app_ui <- function() { + + shiny::addResourcePath("rap", system.file("www", package = "rapbase")) + regTitle <- "rapRegTemplate" + + ui <- shiny::tagList( + shiny::navbarPage( + title = div(a(includeHTML(system.file("www/logo.svg", + package = "rapbase"))), + regTitle), + windowTitle = regTitle, + theme = "rap/bootstrap.css", + id = "tabs", + + shiny::tabPanel("Veiledning", + shiny::mainPanel(width = 12, + shiny::htmlOutput("veiledning", inline = TRUE), + rapbase::appNavbarUserWidget( + user = uiOutput("appUserName"), + organization = uiOutput("appOrgName"), + addUserInfo = TRUE) + ) + ), + shiny::tabPanel("Figur og tabell" + , + shiny::sidebarLayout( + shiny::sidebarPanel(width = 3, + shiny::selectInput(inputId = "var", + label = "Variabel:", + c("mpg", "disp", "hp", "drat", "wt", "qsec")), + shiny::sliderInput(inputId = "bins", + label = "Antall grupper:", + min = 1, + max = 10, + value = 5) + ), + shiny::mainPanel( + shiny::tabsetPanel( + tabPanel("Figur", plotOutput("distPlot")), + tabPanel("Tabell", tableOutput("distTable")) + ) + ) + ) + ), + shiny::tabPanel("Samlerapport" + , + shiny::tabPanel("Fordeling av mpg", + shiny::sidebarLayout( + shiny::sidebarPanel( + width = 3, + shiny::selectInput( + inputId = "varS", + label = "Variabel:", + c("mpg", "disp", "hp", "drat", "wt", "qsec")), + shiny::sliderInput( + inputId = "binsS", + label = "Antall grupper:", + min = 1, + max = 10, + value = 5), + shiny::selectInput( + inputId = "formatS", + label = "Velg format for nedlasting:", + choices = list(PDF = "pdf", HTML = "html") + ), + shiny::downloadButton( + outputId = "downloadSamlerapport", + label = "Last ned!") + ), + shiny::mainPanel( + shiny::uiOutput("samlerapport") + ) + ) + ) + ), + shiny::tabPanel("Abonnement" + , + shiny::sidebarLayout( + shiny::sidebarPanel(width = 3, + shiny::selectInput("subscriptionRep", "Rapport:", + c("Samlerapport1", "Samlerapport2")), + shiny::selectInput("subscriptionFreq", "Frekvens:", + list(Årlig = "Årlig-year", + Kvartalsvis = "Kvartalsvis-quarter", + Månedlig = "Månedlig-month", + Ukentlig = "Ukentlig-week", + Daglig = "Daglig-DSTday"), + selected = "Månedlig-month"), + shiny::actionButton("subscribe", "Bestill", + icon = shiny::icon("paper-plane")) + ), + shiny::mainPanel( + shiny::uiOutput("subscriptionContent") + ) + ) + ), + shiny::tabPanel("Utsending" + , + shiny::sidebarLayout( + shiny::sidebarPanel(width = 3, + shiny::uiOutput("report"), + shiny::uiOutput("freq"), + shiny::textInput("email", "Epostmottakere:"), + shiny::uiOutput("editEmail"), + shiny::htmlOutput("recipients"), + shiny::tags$hr(), + shiny::uiOutput("makeDispatchment") + ), + shiny::mainPanel( + shiny::uiOutput("dispatchmentContent") + ) + ) + ) + + ) # navbarPage + ) # tagList +} diff --git a/R/run_app.R b/R/run_app.R new file mode 100644 index 0000000..4f36544 --- /dev/null +++ b/R/run_app.R @@ -0,0 +1,8 @@ +#' Run the imongr Shiny Application +#' +#' @return An object representeing the imongr app +#' @export + +run_app <- function() { + shiny::shinyApp(ui = app_ui, server = app_server) +} diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..ff84c95 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,11 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +NULL diff --git a/inst/shinyApps/app1/ui.R b/inst/shinyApps/app1/ui.R deleted file mode 100644 index 12a7412..0000000 --- a/inst/shinyApps/app1/ui.R +++ /dev/null @@ -1,119 +0,0 @@ -library(shiny) -library(shinyalert) -library(rapbase) - -addResourcePath("rap", system.file("www", package = "rapbase")) -regTitle <- "rapRegTemplate" - -ui <- shiny::tagList( - shiny::navbarPage( - title = div(a(includeHTML(system.file("www/logo.svg", - package = "rapbase"))), - regTitle), - windowTitle = regTitle, - theme = "rap/bootstrap.css", - id = "tabs", - - shiny::tabPanel("Veiledning", - shiny::mainPanel(width = 12, - shiny::htmlOutput("veiledning", inline = TRUE), - shinyalert::useShinyalert(), - rapbase::appNavbarUserWidget( - user = uiOutput("appUserName"), - organization = uiOutput("appOrgName"), - addUserInfo = TRUE) - ) - ), - shiny::tabPanel("Figur og tabell" - # , - # sidebarLayout( - # sidebarPanel(width = 3, - # selectInput(inputId = "var", - # label = "Variabel:", - # c("mpg", "disp", "hp", "drat", "wt", "qsec")), - # sliderInput(inputId = "bins", - # label = "Antall grupper:", - # min = 1, - # max = 10, - # value = 5) - # ), - # mainPanel( - # tabsetPanel( - # tabPanel("Figur", plotOutput("distPlot")), - # tabPanel("Tabell", tableOutput("distTable")) - # ) - # ) - # ) - ), - shiny::tabPanel("Samlerapport" - # , - # shiny::tabPanel("Fordeling av mpg", - # shiny::sidebarLayout( - # shiny::sidebarPanel( - # width = 3, - # shiny::selectInput( - # inputId = "varS", - # label = "Variabel:", - # c("mpg", "disp", "hp", "drat", "wt", "qsec")), - # shiny::sliderInput( - # inputId = "binsS", - # label = "Antall grupper:", - # min = 1, - # max = 10, - # value = 5), - # shiny::selectInput( - # inputId = "formatS", - # label = "Velg format for nedlasting:", - # choices = list(PDF = "pdf", HTML = "html") - # ), - # shiny::downloadButton( - # outputId = "downloadSamlerapport", - # label = "Last ned!") - # ), - # shiny::mainPanel( - # shiny::uiOutput("samlerapport") - # ) - # ) - # ) - ), - shiny::tabPanel("Abonnement" - # , - # sidebarLayout( - # sidebarPanel(width = 3, - # selectInput("subscriptionRep", "Rapport:", - # c("Samlerapport1", "Samlerapport2")), - # selectInput("subscriptionFreq", "Frekvens:", - # list(Årlig = "Årlig-year", - # Kvartalsvis = "Kvartalsvis-quarter", - # Månedlig = "Månedlig-month", - # Ukentlig = "Ukentlig-week", - # Daglig = "Daglig-DSTday"), - # selected = "Månedlig-month"), - # actionButton("subscribe", "Bestill", - # icon = shiny::icon("paper-plane")) - # ), - # mainPanel( - # uiOutput("subscriptionContent") - # ) - # ) - ), - shiny::tabPanel("Utsending" - # , - # sidebarLayout( - # sidebarPanel(width = 3, - # uiOutput("report"), - # uiOutput("freq"), - # textInput("email", "Epostmottakere:"), - # uiOutput("editEmail"), - # htmlOutput("recipients"), - # tags$hr(), - # uiOutput("makeDispatchment") - # ), - # mainPanel( - # uiOutput("dispatchmentContent") - # ) - # ) - ) - - ) # navbarPage -) # tagList diff --git a/man/app_server.Rd b/man/app_server.Rd new file mode 100644 index 0000000..18a3b88 --- /dev/null +++ b/man/app_server.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/app_server.R +\name{app_server} +\alias{app_server} +\title{Server logic for the rapRegTemplate app} +\usage{ +app_server(input, output, session) +} +\arguments{ +\item{input}{shiny input object} + +\item{output}{shiny output object} + +\item{session}{shiny session object} +} +\value{ +A shiny app server object +} +\description{ +Server logic for the rapRegTemplate app +} diff --git a/man/app_ui.Rd b/man/app_ui.Rd new file mode 100644 index 0000000..d720786 --- /dev/null +++ b/man/app_ui.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/app_ui.R +\name{app_ui} +\alias{app_ui} +\title{Client (ui) for the rapRegTemplate app} +\usage{ +app_ui() +} +\value{ +An shiny app ui object +} +\description{ +Client (ui) for the rapRegTemplate app +} diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..0106fbd --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} diff --git a/man/run_app.Rd b/man/run_app.Rd new file mode 100644 index 0000000..6fa1458 --- /dev/null +++ b/man/run_app.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/run_app.R +\name{run_app} +\alias{run_app} +\title{Run the imongr Shiny Application} +\usage{ +run_app() +} +\value{ +An object representeing the imongr app +} +\description{ +Run the imongr Shiny Application +} diff --git a/tests/testthat.R b/tests/testthat.R index dfa99c9..e888196 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,3 @@ library(testthat) -library(rapRegTemplate) test_check("rapRegTemplate")