简体   繁体   中英

How to implement blurred effect in the top navigation bar of Shiny-app

I was trying to implement the blurred effect on the top navigation bar in my Shiny-app as explained in https://codepen.io/dudleystorey/pen/RNMbGG .

Below is my shiny-app -

library(shiny)
ui =
shinyUI(fluidPage(
      tags$head(
        tags$style(HTML("
          #App_Body {
              height: auto;
              min-height: 10px;
              width: 100%;
              margin: 0 auto;
              padding: 0;
              background-color: rgba(0,0,0,.0);
              font-family: 'Calibri';
              position: relative;
            }

            #blurryscroll { 
              top: 0; left: 0; 
              width: 100%;
              height: 100px;
              overflow: hidden;
              position: fixed;
              filter: blur(4px); 
            }
            #App_Body1 {
              @extend #blurryscroll;
              filter: none; 

              height: 70px;
              width: 100%;
              margin: 0;
              padding: 0;
              background-color: rgba(0,0,0,.0);
              position: fixed;
              top: 0; left: 0; right: 0;
              display: flex; flex-direction: row; text-align: left; align-items: center; justify-content: left;
              border-bottom: 0px solid #6a6a6a;
              z-index: 4;
            }

        "))
      ),
    tags$head(HTML("<script>
                        var pageContent = document.getElementById(\"navbarPage11\"),
                        pagecopy = pageContent.cloneNode(true),
                        blurryContent = document.getElementById(\"blurryscroll\");
                        blurryContent.appendChild(pagecopy);
                        window.onscroll = function() { blurryContent.scrollTop = window.pageYOffset; }
                    </script>
            ")),

    div(id = "App_Body",
        div(id = "blurryscroll", `aria-hidden` = TRUE),
        div(id = "App_Body1",
            HTML("What is Lorem Ipsum?
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
        )
    ),

    navbarPage(id = "navbarPage1", "Analysis navbarPage1", 
                        tabPanel(tabName = "Page1", 
                                    "Page1",
                                    div(id = "navbarPage11", style = "height: 2000px; width: 20%; background-color: rgba(0,0,0,.3);",
                                        HTML("What is Lorem Ipsum?
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
                                    ) 
                                )
                )
))

server = function(input, output, session){}

shinyApp(ui = ui, server = server)

As can be seen there, my App failed to bring the blurred effect despite implementing similar approach explained in the link.

Can you please help me to understand what exactly went wrong with my approach?

Any pointer will be highly appreciated.

Edited based on reply from Stéphane Laurent -

Modified app -

ui =
shinyUI(fluidPage(
      tags$head(
        tags$style(HTML("
          #App_Body {
  height: auto;
  min-height: 10px;
  width: 100%;
  margin: 0 auto;
  padding: 0;
  background-color: rgba(0, 0, 0, .0);
  font-family: 'Calibri';
  position: relative;
}

#blurryscroll, #App_Body1 {
  top: 0;
  left: 0;
  width: 100%;
  height: 5rem;
  overflow: hidden;
  position: fixed; 
  -webkit-filter: blur(4px);
  filter: blur(4px);
}
#App_Body1 {
  height: 70px;
  width: 100%;
  margin: 0;
  padding: 0;
  background-color: rgba(0, 0, 0, .0);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: row;
  text-align: left;
  align-items: center;
  justify-content: left;
  border-bottom: 0px solid #6a6a6a;
  z-index: 4;
}

        "))
      ),
    tags$head(HTML("<script>
                        $(document).ready(function(){
  var pageContent = document.getElementById(\"navbarPage1\"),
      pagecopy = pageContent.cloneNode(true),
      blurryContent = document.getElementById(\"blurryscroll\");
  blurryContent.appendChild(pagecopy);
  window.onscroll = function() { blurryContent.scrollTop = window.pageYOffset; };
});
                    </script>
            ")),

    div(id = "App_Body",
        div(id = "blurryscroll", `aria-hidden` = TRUE),
        div(id = "App_Body1",
            HTML("What is Lorem Ipsum?
                    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
                )
    ),
    div(id="content",
        navbarPage(id = "navbarPage1", "Analysis navbarPage1", 
                            tabPanel(tabName = "Page1", 
                                        "Page1",
                                        div(id = "navbarPage11", style = "height: 2000px; width: 20%; background-color: rgba(0,0,0,.3)",
                                            HTML("What is Lorem Ipsum?
                                                    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
                                                )
                                        ) 
                                    )
                    ))
))

server = function(input, output, session){}

shinyApp(ui = ui, server = server)

But with this elements of App_Body1 getting blurred, however my goal was to blur elements of content of navbarPage1 .

1) You copied the SCSS code, instead of the CSS code ( @extend is not CSS). Here is the CSS:

#App_Body {
  height: auto;
  min-height: 10px;
  width: 100%;
  margin: 0 auto;
  padding: 0;
  background-color: rgba(0, 0, 0, .0);
  font-family: 'Calibri';
  position: relative;
}

#blurryscroll, #App_Body1 {
  top: 0;
  left: 0;
  width: 100%;
  height: 5rem;
  overflow: hidden;
  position: fixed; 
  -webkit-filter: blur(4px);
  filter: blur(4px);
}
#App_Body1 {
  height: 70px;
  width: 100%;
  margin: 0;
  padding: 0;
  background-color: rgba(0, 0, 0, .0);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: row;
  text-align: left;
  align-items: center;
  justify-content: left;
  border-bottom: 0px solid #6a6a6a;
  z-index: 4;
}

2) You typed navbarPage11 instead of navbarPage1 in the JS code.

3) You have to encapsulate the JS code in a $(document).ready(function(){...}); . Here is the JS code:

$(document).ready(function(){
  var pageContent = document.getElementById(\"navbarPage1\"),
      pagecopy = pageContent.cloneNode(true),
      blurryContent = document.getElementById(\"blurryscroll\");
  blurryContent.appendChild(pagecopy);
  window.onscroll = function() { blurryContent.scrollTop = window.pageYOffset; };
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM