Open wkdavis opened 5 years ago
Interestingly if you change the outputID in ui and the output$body to text other than "body", it works. not sure why.
uiOutput("body2")
@kevin041811 That's an interesting observation. It made me think that it has something to do with the fact that "body" is also an HTML tag, so I tried a few other examples.
I'm thinking there is some fuzzy-matching logic going on somewhere that is looking for HTML tags or something like HTML tags, but I'm not sure. For instance, I don't know why body2 works but div2 does not.
This looks very similar to what I've reported earlier today (#335), might be a duplicate.
Hello,
I'm not too sure how I would translate this fix (rename body into anything different in uiOutput(body)
, since I already use something different (uiOutput(TABUI)
which is hosting all my tabItems
). Have you got by any chance to the bottom of this ?
I'm still stuck with this issue which I describe also in #335 .
Thanks ahead of time for your help :)
I'm having a similar problem, except my UI isn't dynamically generated--but even when I add a static UI component as a menuSubitem or just by itself under one of the menuItems, the selected tab does not display on init. I posted about this issue here on RStudio community, along with a reproducible UI example. Is there a fix for this yet?
Thank you!
Have a look at #71, basically adding
isolate({updateTabItems(session, "sidebarmenu_id", "init_tabname")})
should do the trick with sidebarmenu_id
being the id of my sidebarmenu, and init_tabname
the tabName
of the tab I should get upon firing the app.
Thank you so much for the response @homer3018! You're right that this fix works really well to get the menuItem to display initially (which is awesome). However, for some reason the menuItem still doesn't read as "selected" from the server's point of view, which means that when I write other code that depends on input$sidebarmenu_id
being equal to init_tabname
(i.e. code that depends on which menuItem is selected), that code won't work. Here is an example, where I've just added a bit in the server to print a message to the console when each menuItem is selected. You'll see that even while the first tab, "mapView", does now open on init, no matter how much I click between the two tabs you will never see the message "Map view has been selected" in the console, and on init the "Social variables view has been selected" message displays even though the map view tab shows up:
library(shinyjs)
library(shinyWidgets)
library(shinydashboard)
library(shinydashboardPlus)
library(dashboardthemes)
source("dashboardFunctions.R")
ui <- dashboardPagePlus(
useShinyjs(),
## Define dashboard header: title, icon for right sidebar, etc.
header = dashboardHeaderPlus(
title = "Dashboard",
enable_rightsidebar = TRUE,
rightSidebarIcon = "sliders"
),
## Define left sidebar and menu options
sidebar = dashboardSidebar(
sidebarMenu(
id = "leftSidebar",
menuItem("Map view", tabName = "mapView", icon = icon("map"), selected = TRUE, startExpanded = TRUE,
# add a menuSubItem
selectInput("survey", "Survey",
choices = c("5", "5b", "6", "6b", "7", "8", "9", "11", "12"),
selected = "11",
multiple = FALSE)
),
menuItem("Social variables", tabName = "socialVariables", icon = icon("gears"))
)
),
## Define dashboard body (maps/graphs)
body = dashboardBody(
shinyDashboardThemes(theme = "grey_dark"
),
tabItems(tabItem(tabName = "map", p("[Insert map here]")),
tabItem(tabName = "socialCharts", p("[Insert charts here]"))
)
)
)
server <- function(session, input, output) {
observe({
if(req(input$leftSidebar) == "mapView"){
message("Map view has been selected.")
}else if(req(input$leftSidebar) == "socialVariables"){
message("Social variables view has been selected.")
}
})
isolate({updateTabItems(session, "leftSidebar", "mapView")})
}
shinyApp(ui = ui, server = server)
I answered the above here.
@kaijagahm i have the same problem... when i run the app, the first tab (or menu item) is selected, but the content do not load in the body... did you find the solution ?
Honestly, it was so long ago that I barely remember. I think I used the solution described in the post linked right above your comment: https://community.rstudio.com/t/shinydashboard-wrong-menuitem-selected-after-adding-menusubitem/82561/3?u=ismirsehregal. Did you already try that?
This is a similar case to #71, but when the body of the dashboard is also dynamically generated the app fails to display the content of the first tab, even when
selected = TRUE
.Session info:
I dug into the HTML and it looks like it recognizes that the tab should be active, based on the class of the item in the sidebar menu (
<li class="active">
).But when I inspect the actual panel:
I find that it has class "tab-pane" when I think the class should be "active" based on the css (this is line 4137-4142 from bootstrap.css):
from the following version of bootstrap: