TakeCareApp/app/app.R

139 lines
4.4 KiB
R
Raw Normal View History

2020-11-27 19:14:20 +01:00
library(shiny)
2020-12-04 18:06:31 +01:00
library(shiny.router)
2020-12-03 11:39:38 +01:00
library(magrittr)
library(ggplot2)
library(plotly)
library(DT)
2020-12-06 19:45:27 +01:00
library(shinyjs)
2020-11-27 19:14:20 +01:00
2020-12-04 18:06:31 +01:00
#source(".R/home_module.R",encoding="utf-8")
#source(".R/about_module.R",encoding="utf-8")
#source(".R/profil_module.R",encoding="utf-8")
2020-12-04 18:06:31 +01:00
source("routing_module.R",encoding="utf-8")
2020-11-27 19:14:20 +01:00
2020-12-06 19:45:27 +01:00
ui <- fluidPage(
2020-12-14 13:47:03 +01:00
useShinyjs(),
tags$head(
2020-12-19 23:13:44 +01:00
tags$script(src="js.cookie.js"),
2020-12-20 15:46:02 +01:00
tags$script('var token = sessionStorage.getItem(\'token\');
$(document).on("shiny:sessioninitialized",function(event){
Shiny.onInputChange("token", token);});'),
tags$script('Shiny.addCustomMessageHandler("tokenHandler",
2020-12-19 23:13:44 +01:00
function(token) {
2020-12-20 15:46:02 +01:00
sessionStorage.setItem(\'token\', token);
Shiny.onInputChange("token", token);
2020-12-19 23:13:44 +01:00
}
);')
2020-12-14 13:47:03 +01:00
),
uiOutput("logged"),
2020-12-06 19:45:27 +01:00
router$ui)
2020-12-04 18:06:31 +01:00
server <- shinyServer(function(input, output, session){
2020-12-14 13:47:03 +01:00
output$logged<-renderUI({
if(is.null(input$token)){
fluidRow(
inlineCSS(list(.clicked = "background-color: #008375 !important")),
column(12,
navbarPage("",
tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))),
2020-12-19 20:18:46 +01:00
tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("firmy"))),
2020-12-14 13:47:03 +01:00
tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))),
tabPanel(a("Zaloguj",id="tab3",class="tab-link", href = route_link("login"))),
2020-12-19 19:25:04 +01:00
tabPanel(a("Rejestracja",id="tab4",class="tab-link", href = route_link("register")))),
2020-12-14 13:47:03 +01:00
)
)
}else{
fluidRow(
inlineCSS(list(.clicked = "background-color: #008375 !important")),
column(12,
navbarPage("",
tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))),
tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("profil"))),
tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))),
2020-12-19 22:21:48 +01:00
tabPanel(a("Kalkulator", id ="tab5",class="tab-link", href = route_link("calculator"))),
2020-12-14 13:47:03 +01:00
tabPanel(a("Wyloguj",id="tab3",class = "tab-link")),
2020-12-19 19:25:04 +01:00
tabPanel(a("Profil",id="tab4",class="tab-link", href = route_link("profil")))),
2020-12-14 13:47:03 +01:00
)
)
}
})
2020-12-06 19:45:27 +01:00
shinyjs::onclick(id="takeCareApp",expr = {
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
2020-12-12 12:38:54 +01:00
shinyjs::removeCssClass(id="tab4",class = "clicked")
2020-12-06 19:45:27 +01:00
})
shinyjs::onclick(id="tab1",expr = {
shinyjs::addCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
2020-12-12 12:38:54 +01:00
shinyjs::removeCssClass(id="tab4",class = "clicked")
2020-12-06 19:45:27 +01:00
})
shinyjs::onclick(id="tab2",expr = {
shinyjs::addCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
2020-12-12 12:38:54 +01:00
shinyjs::removeCssClass(id="tab4",class = "clicked")
2020-12-06 19:45:27 +01:00
})
shinyjs::onclick(id="tab3",expr = {
2020-12-14 13:47:03 +01:00
if(is.null(input$token)){
shinyjs::addCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
}else{
2020-12-20 15:46:02 +01:00
shinyjs::runjs( 'sessionStorage.removeItem(\'token\');
2020-12-14 13:47:03 +01:00
Shiny.onInputChange("token", null);
window.location.replace(\'/#!/login\');')
}
2020-12-06 19:45:27 +01:00
})
2020-12-12 12:38:54 +01:00
shinyjs::onclick(id="tab4",expr = {
shinyjs::addCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
})
2020-12-06 19:45:27 +01:00
2020-12-04 18:06:31 +01:00
router$server(input, output, session)
})
2020-11-27 19:14:20 +01:00
2020-12-03 11:39:38 +01:00
shinyApp(ui=ui,server=server)