Created
February 26, 2016 13:24
-
-
Save byzheng/074c3c1ff75ea9f951f5 to your computer and use it in GitHub Desktop.
leaflet and shinydashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(leaflet) | |
library(shiny) | |
library(shinydashboard) | |
# header board | |
header <- dashboardHeader( | |
title = 'Pheno-Copter' | |
# task list for status of data processing | |
, dropdownMenuOutput('task_menu')) | |
# Side bar boardy | |
sidebar <- dashboardSidebar( | |
sidebarMenu( | |
id = 'menu_tabs' | |
, menuItem('menu1', tabName = 'menu1') | |
, menuItem('menu2', tabName = 'menu2') | |
) | |
) | |
# Body board | |
body <- dashboardBody( | |
tabItems( | |
tabItem( | |
tabName = 'menu1' | |
, tags$a( | |
id = "mydiv", href = "#", 'click me', | |
onclick = 'Shiny.onInputChange("mydata", Math.random());') | |
), | |
tabItem( | |
tabName = 'menu2' | |
, leafletOutput('map') | |
, verbatimTextOutput('summary') | |
) | |
) | |
) | |
# Shiny UI | |
ui <- dashboardPage( | |
title = 'test', | |
dashboardHeader(), | |
sidebar, | |
body | |
) | |
server <- function(input, output, session) { | |
observe({ | |
req(input$mydata) | |
updateTabItems(session, 'menu_tabs', 'menu2') | |
}) | |
output$map <- renderLeaflet({ | |
leaflet() %>% | |
addTiles(options = tileOptions(maxZoom = 28, maxNativeZoom = 19), | |
group = 'OSM') | |
}) | |
output$summary <- renderPrint({ | |
print(input$mydata) | |
print(leafletProxy('map')$id) | |
}) | |
observe({ | |
req(input$mydata) | |
proxy <- leafletProxy('map') | |
print(proxy$id) | |
proxy %>% | |
setView(runif(1) * 30 +2, runif(1) * 30 + 2, 7) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment