TakeCareApp/app/app.R

130 lines
4.2 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(
tags$script(src="js.cookie.js")
),
# tags$script('var cookie = Cookies.get(\'token\');
# $(document).on("shiny:sessioninitialized",function(event){
# Shiny.onInputChange("token", cookie);});')),
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"))),
2020-12-19 19:25:04 +01:00
tabPanel(a("Obliczenia", id ="tab5",class="tab-link", href = route_link("calculator"))),
2020-12-14 13:47:03 +01:00
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"))),
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{
shinyjs::runjs( 'Cookies.remove(\'token\');
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)