Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shiny - update layer refocuses map #93

Closed
SymbolixAU opened this issue Dec 3, 2018 · 3 comments
Closed

shiny - update layer refocuses map #93

SymbolixAU opened this issue Dec 3, 2018 · 3 comments
Milestone

Comments

@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Dec 3, 2018

This happens when you've initialised the map with data, then use an observeEvent() to change it.

(and it's almost replicating the behaviour we sometimes see where the layer is 'sticky'. Maybe they're related?)

library(shiny)
library(shinydashboard)
library(sf)

ui <- dashboardPage(
	dashboardHeader()
	, dashboardSidebar()
	, dashboardBody(
		mapdeckOutput(
			outputId = "map"
			, height = "600"
		)
		, actionButton(
			inputId = "btn"
			, label = "btn"
		)
	)
)
server <- function( input, output ) {
	
	output$map <- renderMapdeck({

		mapdeck( style = mapdeck_style("dark") ) %>%
		add_path( data = roads[1:500, ] )
	})
	
	observeEvent({input$btn},{
		
		mapdeck_update( map_id = "map" ) %>%
			add_path( data = roads[500:1000, ], update_view = FALSE )
	})
}

shinyApp( ui, server )
@SymbolixAU SymbolixAU added this to the v0.2.0 milestone Dec 3, 2018
@SymbolixAU SymbolixAU self-assigned this Dec 3, 2018
@SymbolixAU
Copy link
Collaborator Author

SymbolixAU commented Dec 3, 2018

found the culprit - it's my update_view functions & logic.

For some reason the viewState is not keeping a reference to the auto-calcualted "location" in the first add_path(), so on the button presses it's not being set at the correct location, and requires interacting with the map to force a re-draw (or using update_view = TRUE in the subsequent add_path() calls

Time for a re-think...

It seems to be the solution is a recommendation:

  • If you'll be adding & removing layers dynamically and want to use update_view = FALSE each udpate, don't supply data to the original mapdeck() call

@SymbolixAU SymbolixAU modified the milestones: v0.2.0, v1.0 Dec 11, 2018
@SymbolixAU
Copy link
Collaborator Author

@SymbolixAU
Copy link
Collaborator Author

related - #137
but I think this too is fixed now.

@dcooley dcooley closed this as completed Jun 13, 2019
@SymbolixAU SymbolixAU removed their assignment Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant