daattali / shinyjs

💡 Easily improve the user experience of your Shiny apps in seconds
https://deanattali.com/shinyjs
Other
734 stars 119 forks source link

show sets focus on element #148

Closed thothal closed 6 years ago

thothal commented 6 years ago

Problem

I am using a shinydashboard design, where I want to hide/show a menu item. This works in principle, but when I show the element the focus is set to the corresponding tabItem which is an unwanted behavior. Is this an intended behavior? My workaround of adding updateTabItems(session, "tabs", "item1") works but generates a flickering. Any better ideas?

Reprex

library(shiny)
library(shinyjs)
library(shinydashboard)

ui <- dashboardPage(
   dashboardHeader(title = "Dashboard"),
   dashboardSidebar(
      sidebarMenu(id = "tabs",
                  menuItem("Item 1", tabName = "item1"),
                  menuItem("Item 2", tabName = "item2")
      ),
      checkboxInput("foo", "Show Item2", TRUE)
   ),
   dashboardBody(
      useShinyjs(),
      tabItems(
         tabItem("item1", h1("Item 1")),
         tabItem("item2", h1("Item 2"))
      )
   )
)

server <- function(input, output) {
    observe({
      toggle(condition = input$foo, selector = "a[data-value=item2]")
    })
}

runApp(shinyApp(ui = ui, server = server))
daattali commented 6 years ago

Either I'm not understanding what you're describing, or it's not happening to me. I tried your code, and the tab never changes

https://imgur.com/a/gvMp4

thothal commented 6 years ago

I tried it with both IE11 and Chrome. I made a little video showing what is happening on my machine. Any other info you would need me to provide to track down this issue?

https://i.imgur.com/XZEQLfQ.mp4

daattali commented 6 years ago

That is strange. I'm sorry I can't think of any reason why this is happening. I suppose the first place to start looking at debugging is by looking at the javascript console to see if anything is happening there, and to look at the HTML page DOM to see if something strange is happening there as well, but I don't really know what I'd be looking for. I'm also working on a fewworkshops this month and am very behind on client projects so I don't have time to look into this. Very strange though, I'm sorry, no idea!


Dean Attali President & CEO AttaliTech Ltd http://AttaliTech.com http://attalitech.com

Attend my 4-day workshop: Learn how to analyze data with R and create Shiny apps. 15% discount to existing clients. Register here! https://www.eventbrite.com/e/modern-r-data-processing-visualization-and-reporting-with-r-tickets-39862492789?aff=deanemail

On 8 December 2017 at 05:13, thothal notifications@github.com wrote:

I tried it with both IE11 and Chrome. I made a little video showing what is happening on my machine. Any other info you would need me to provide to track down this issue?

Shiny_Dashboard_IE.zip https://github.com/daattali/shinyjs/files/1542255/Shiny_Dashboard_IE.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daattali/shinyjs/issues/148#issuecomment-350226206, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6IFM-LrsaZ0i7jgIzcocQnSzW8TrkLks5s-QvhgaJpZM4Q5z-R .

thothal commented 6 years ago

Just for the record, tried it @home as well with Safari, same story. Just because I am curious, which browser were you using?

daattali commented 6 years ago

Chrome on windows 7. Perhaps its the package versions? @oganm you mind trying out the code above and see if you see the problem, if you have a few minutes? Sorry to summon you out of nowhere...

On Dec 8, 2017 5:41 PM, "thothal" notifications@github.com wrote:

Just for the record, tried it @home as well with Safari, same story. Just because I am curious, which browser were you using?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daattali/shinyjs/issues/148#issuecomment-350390386, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6IFB4kPc3R2NhbcukqRkIV_eLhcQ8oks5s-bsNgaJpZM4Q5z-R .

oganm commented 6 years ago

t'is fine. What package versions do you need? and do you need windows or ubuntu?

daattali commented 6 years ago

Any and any. Just wondering if anyone can reproduce

On Dec 8, 2017 8:56 PM, "Burak Ogan Mancarci" notifications@github.com wrote:

t'is fine. What package versions do you need? and do you need windows or ubuntu?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daattali/shinyjs/issues/148#issuecomment-350415117, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6IFAcqVgwkAllv-i70-qJ5wTf2425Xks5s-ejDgaJpZM4Q5z-R .

oganm commented 6 years ago

Happens to me too. Everything except R itself is updated to latest version (3.3.2)

daattali commented 6 years ago

Interesting. When i get my hands on another computer I'll try looking into it a bit. Thanks for reporting

On Dec 8, 2017 9:36 PM, "Burak Ogan Mancarci" notifications@github.com wrote:

Happens to me too. Everything except R itself is updated to latest version (3.3.2)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daattali/shinyjs/issues/148#issuecomment-350417722, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6IFIhvEv_ZUGX4dt7cprcqxgpW-LSAks5s-fJJgaJpZM4Q5z-R .

calligross commented 6 years ago

+1

sessionInfo() R version 3.4.3 (2017-11-30) Platform: x86_64-apple-darwin17.3.0 (64-bit) Running under: macOS High Sierra 10.13.2

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /usr/local/Cellar/openblas/0.2.20/lib/libopenblasp-r0.2.20.dylib

locale: [1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] ESCBhelper_0.1.0 writexl_0.2 ggrepel_0.7.0 scales_0.5.0 ggplot2_2.2.1 dplyr_0.7.4
[7] shinydashboard_0.6.1 shinyjs_0.9.1 shiny_1.0.5 bindrcpp_0.2

loaded via a namespace (and not attached): [1] Rcpp_0.12.14 lubridate_1.7.1 tidyr_0.7.2 assertthat_0.2.0 digest_0.6.13 utf8_1.1.2 V8_1.5 mime_0.5
[9] R6_2.2.2 cellranger_1.1.0 plyr_1.8.4 httr_1.3.1 pillar_1.0.1 rlang_0.1.6 lazyeval_0.2.1 curl_3.1
[17] bcrypt_1.0 readxl_1.0.0 rstudioapi_0.7 miniUI_0.1.1 DT_0.2 labeling_0.3 stringr_1.2.0 htmlwidgets_0.9 [25] munsell_0.4.3 compiler_3.4.3 httpuv_1.3.5 pkgconfig_2.0.1 htmltools_0.3.6 openssl_0.9.9 tibble_1.4.1 crayon_1.3.4
[33] grid_3.4.3 jsonlite_1.5 xtable_1.8-2 gtable_0.2.0 magrittr_1.5 cli_1.0.0 stringi_1.1.6 reshape2_1.4.3
[41] xml2_1.1.1 tools_3.4.3 glue_1.2.0 markdown_0.8 purrr_0.2.4 yaml_2.1.16 colorspace_1.3-2 rvest_0.3.2
[49] bindr_0.1

daattali commented 6 years ago

I was able to reproduce this now. I believe it's a shiny bug (not shinyjs), because after debugging I noticed that the JS call that actually shows the tab is ok, but then calling .trigger("shown") on the tab in order to inform shiny that the tab is shown caused it to get selected. I will file a report with shiny

daattali commented 6 years ago

This issue will be solved automatically when https://github.com/rstudio/shiny/issues/1991 is solved so I'm closing it as it's not a shinyjs issue