From 51e427a6b52b68b3e2190296d375383287d1cc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Piskorski?= Date: Fri, 4 Dec 2020 18:06:31 +0100 Subject: [PATCH] router basic --- app/about_module.R | 50 +++++++++++++++++ app/app.R | 131 ++++--------------------------------------- app/home_module.R | 53 +++++++++++++++++ app/profil_module.R | 126 +++++++++++++++++++++++++++++++++++++++++ app/routing_module.R | 24 ++++++++ 5 files changed, 265 insertions(+), 119 deletions(-) create mode 100644 app/about_module.R create mode 100644 app/home_module.R create mode 100644 app/profil_module.R create mode 100644 app/routing_module.R diff --git a/app/about_module.R b/app/about_module.R new file mode 100644 index 0000000..31e3da6 --- /dev/null +++ b/app/about_module.R @@ -0,0 +1,50 @@ +library(shiny) +library(magrittr) +library(ggplot2) +library(plotly) +library(DT) + +aboutUI <- function(id) { + ns <- NS(id) + fluidPage( + tags$head( + tags$style(HTML(" + @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700'); + @import url('//fonts.googleapis.com/css2?family=Fjalla+One'); + + + "))), + + theme = "style.css", + + fluidRow( + column(12, + navbarPage("", + tabPanel("TakeCareApp"), + tabPanel("Firmy"), + tabPanel("O nas"), + tabPanel("Zaloguj")), + + )), + # App title ---- + + fluidRow(column(12," ABOUT")%>% tagAppendAttributes(id = 'column-content') + ) %>% tagAppendAttributes(id = 'row-content'), + + + + fluidRow( + column(12, + tags$span("© Copyright Wszystkie prawa zastrzeżone."))%>% tagAppendAttributes(id = 'column-copyright'), + + )%>% tagAppendAttributes(id = 'row-footer') + + + ) +} +aboutServer <- function(input, output) { + + + +} + diff --git a/app/app.R b/app/app.R index 1ca7d9d..f2e3bc7 100644 --- a/app/app.R +++ b/app/app.R @@ -1,130 +1,23 @@ library(shiny) +library(shiny.router) library(magrittr) library(ggplot2) library(plotly) library(DT) +#source(".R/home_module.R",encoding="utf-8") +#source(".R/about_module.R",encoding="utf-8") +#source(".R/profil_module.R",encoding="utf-8") -ui <- fluidPage( - tags$head( - tags$style(HTML(" - @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700'); - @import url('//fonts.googleapis.com/css2?family=Fjalla+One'); +source("routing_module.R",encoding="utf-8") - - "))), - - theme = "style.css", - - fluidRow( - column(12, - navbarPage("", - tabPanel("TakeCareApp"), - tabPanel("Firmy"), - tabPanel("O nas"), - tabPanel("Zaloguj")), - - )), - # App title ---- - titlePanel(h1("TakeCareApp", align = "center")), - h4("Aplikacja wspomagajaca diagnozowanie i monitorowanie stanu zdrowia", align = "center"), - - - fluidRow( - column(3, - tags$div("Panel sterowania") %>% tagAppendAttributes(class="panel-title") - - )%>% tagAppendAttributes(id = 'column-panel'), - column(9, - tabsetPanel(type = "tabs", - tabPanel("Zakładka 1", tags$div(plotlyOutput("plot1",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), - tabPanel("Zakładka 2", tags$div(plotlyOutput("plot2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), - tabPanel("Zakładka 3", tags$div(plotlyOutput("plot3",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), - tabPanel("Zakładka 4", tags$div(plotlyOutput("plot4",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), - tabPanel("Zakładka 5", tags$div(DT::dataTableOutput("table1",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), - tabPanel("Zakładka 6", tags$div(DT::dataTableOutput("table2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')) - ))%>% tagAppendAttributes(id = 'column-content') - ) %>% tagAppendAttributes(id = 'row-content'), - - - - fluidRow( - column(12, - tags$span("© Copyright Wszystkie prawa zastrzeżone."))%>% tagAppendAttributes(id = 'column-copyright'), - - )%>% tagAppendAttributes(id = 'row-footer') - - -) -server <- function(input, output) { - - output$plot1 <- renderPlotly({ - - g<-ggplot(mpg) + - geom_point(mapping = aes(x = displ, y = hwy)) - - gg<-ggplotly(g) - - gg - - }) - - output$plot2 <- renderPlotly({ - - g<-ggplot(data = mpg, mapping = aes(x = cty, y = hwy)) + - geom_jitter() - - gg<-ggplotly(g) - - gg - - }) - - output$plot3 <- renderPlotly({ - - g<-ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = drv)) + - geom_point() + - geom_smooth(se = FALSE) - - gg<-ggplotly(g) - - gg - - }) - - output$plot4 <- renderPlotly({ - - g<-ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + - geom_point(mapping = aes(color=drv)) + - geom_smooth(se = FALSE) - - gg<-ggplotly(g) - - gg - - }) - - pl <- list( - sSearch = "Szukaj", - sInfo="Wyniki od _START_ do _END_ z _TOTAL_ rekordów", - sZeroRecords="Brak rekordów", - sEmptyTable="Pusta tabela", - oPaginate= list( - sFirst="Pierwsza", sPrevious="Poprzednia",sLast="Ostatnia", sNext="Następna" - ), - sLengthMenu = "Pokaż _MENU_ rekordów na stronie" - ) - - output$table1 <- DT::renderDataTable(iris,options = list(scrollX = TRUE,language=pl)) - - - table<-DT::renderDataTable(mpg,options = list(scrollX = TRUE,language=pl)) - output$table2 <- table - - - - -} +ui <- router$ui + + + +server <- shinyServer(function(input, output, session){ + router$server(input, output, session) +}) shinyApp(ui=ui,server=server) \ No newline at end of file diff --git a/app/home_module.R b/app/home_module.R new file mode 100644 index 0000000..1a6601d --- /dev/null +++ b/app/home_module.R @@ -0,0 +1,53 @@ +library(shiny) +library(magrittr) +library(ggplot2) +library(plotly) +library(DT) + +homeUI <- function(id) { + ns <- NS(id) + fluidPage( + tags$head( + tags$style(HTML(" + @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700'); + @import url('//fonts.googleapis.com/css2?family=Fjalla+One'); + + + "))), + + theme = "style.css", + + fluidRow( + column(12, + navbarPage("", + tabPanel("TakeCareApp"), + tabPanel("Firmy"), + tabPanel("O nas"), + tabPanel("Zaloguj")), + + )), + # App title ---- + # App title ---- + titlePanel(h1("TakeCareApp", align = "center")), + h4("Aplikacja wspomagajaca diagnozowanie i monitorowanie stanu zdrowia", align = "center"), + + fluidRow(column(12," HOME")%>% tagAppendAttributes(id = 'column-content') + ) %>% tagAppendAttributes(id = 'row-content'), + + + + fluidRow( + column(12, + tags$span("© Copyright Wszystkie prawa zastrzeżone."))%>% tagAppendAttributes(id = 'column-copyright'), + + )%>% tagAppendAttributes(id = 'row-footer') + + +) +} +homeServer <- function(input, output) { + + + +} + diff --git a/app/profil_module.R b/app/profil_module.R new file mode 100644 index 0000000..c066588 --- /dev/null +++ b/app/profil_module.R @@ -0,0 +1,126 @@ +library(shiny) +library(magrittr) +library(ggplot2) +library(plotly) +library(DT) + +profilUI <- function(id) { + ns <- NS(id) + fluidPage( + tags$head( + tags$style(HTML(" + @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700'); + @import url('//fonts.googleapis.com/css2?family=Fjalla+One'); + + + "))), + + theme = "style.css", + + fluidRow( + column(12, + navbarPage("", + tabPanel("TakeCareApp"), + tabPanel("Firmy"), + tabPanel("O nas"), + tabPanel("Zaloguj")), + + )), + # App title ---- + + fluidRow( + column(3, + tags$div("Panel sterowania") %>% tagAppendAttributes(class="panel-title") + + )%>% tagAppendAttributes(id = 'column-panel'), + column(9, + tabsetPanel(type = "tabs", + tabPanel("Zakładka 1", tags$div(plotlyOutput("plot1",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), + tabPanel("Zakładka 2", tags$div(plotlyOutput("plot2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), + tabPanel("Zakładka 3", tags$div(plotlyOutput("plot3",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), + tabPanel("Zakładka 4", tags$div(plotlyOutput("plot4",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), + tabPanel("Zakładka 5", tags$div(DT::dataTableOutput("table1",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), + tabPanel("Zakładka 6", tags$div(DT::dataTableOutput("table2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')) + ))%>% tagAppendAttributes(id = 'column-content') + ) %>% tagAppendAttributes(id = 'row-content'), + + + + fluidRow( + column(12, + tags$span("© Copyright Wszystkie prawa zastrzeżone."))%>% tagAppendAttributes(id = 'column-copyright'), + + )%>% tagAppendAttributes(id = 'row-footer') + + +)} + +profilServer <- function(input, output) { + + output$plot1 <- renderPlotly({ + + g<-ggplot(mpg) + + geom_point(mapping = aes(x = displ, y = hwy)) + + gg<-ggplotly(g) + + gg + + }) + + output$plot2 <- renderPlotly({ + + g<-ggplot(data = mpg, mapping = aes(x = cty, y = hwy)) + + geom_jitter() + + gg<-ggplotly(g) + + gg + + }) + + output$plot3 <- renderPlotly({ + + g<-ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = drv)) + + geom_point() + + geom_smooth(se = FALSE) + + gg<-ggplotly(g) + + gg + + }) + + output$plot4 <- renderPlotly({ + + g<-ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + + geom_point(mapping = aes(color=drv)) + + geom_smooth(se = FALSE) + + gg<-ggplotly(g) + + gg + + }) + + pl <- list( + sSearch = "Szukaj", + sInfo="Wyniki od _START_ do _END_ z _TOTAL_ rekordów", + sZeroRecords="Brak rekordów", + sEmptyTable="Pusta tabela", + oPaginate= list( + sFirst="Pierwsza", sPrevious="Poprzednia",sLast="Ostatnia", sNext="Następna" + ), + sLengthMenu = "Pokaż _MENU_ rekordów na stronie" + ) + + output$table1 <- DT::renderDataTable(iris,options = list(scrollX = TRUE,language=pl)) + + + table<-DT::renderDataTable(mpg,options = list(scrollX = TRUE,language=pl)) + output$table2 <- table + + + + +} diff --git a/app/routing_module.R b/app/routing_module.R new file mode 100644 index 0000000..89e30e7 --- /dev/null +++ b/app/routing_module.R @@ -0,0 +1,24 @@ +library(shiny) +library(shiny.router) +library(magrittr) +library(ggplot2) +library(plotly) +library(DT) + +source("home_module.R",encoding="utf-8") +source("about_module.R",encoding="utf-8") +source("profil_module.R",encoding="utf-8") + + + +home_page <-homeUI(id="home") +about_page <-aboutUI(id="about") +profil_page <-profilUI(id="profil") + +router <- make_router( + route("home", home_page,homeServer), + route("about", about_page,aboutServer), + route("profil", profil_page,profilServer) +) + +