Last active
February 26, 2016 12:35
-
-
Save byzheng/4dc969043439bf44217d to your computer and use it in GitHub Desktop.
test leaflet with dashboard: app1.r is working, but app2.R gives an error in console (Couldn't find map with id map)
This file contains hidden or 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(shiny) | |
library(shinydashboard) | |
# header board | |
header <- dashboardHeader( | |
title = 'Pheno-Copter' | |
# task list for status of data processing | |
, dropdownMenuOutput('task_menu')) | |
# Side bar board | |
sidebar <- dashboardSidebar( | |
sidebarMenu( | |
id = 'menu_tabs' | |
, menuItem('menu1', tabName = 'menu1') | |
, menuSubItem('menu2', tabName = 'menu2') | |
) | |
) | |
# Body board | |
body <- dashboardBody( | |
tabItems( | |
tabItem( | |
tabName = 'menu1' | |
, tags$a( | |
id = "mydiv", href = "#", 'click me', | |
onclick = 'Shiny.onInputChange("mydata", Math.random());'), | |
leafletOutput('map') | |
), | |
tabItem( | |
tabName = 'image_viewer' | |
) | |
) | |
) | |
# Shiny UI | |
ui <- dashboardPage( | |
title = 'test', | |
dashboardHeader(), | |
sidebar, | |
body | |
) | |
server <- function(input, output, session) { | |
output$map <- renderLeaflet({ | |
leaflet() %>% | |
addTiles(options = tileOptions(maxZoom = 28, maxNativeZoom = 19), | |
group = 'OSM') | |
}) | |
observe({ | |
input$mydata | |
proxy <- leafletProxy('map') | |
proxy %>% | |
setView(runif(1) * 10, runif(1) * 10, 7) | |
}) | |
} | |
shinyApp(ui, server) | |
This file contains hidden or 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(shiny) | |
library(shinydashboard) | |
# header board | |
header <- dashboardHeader( | |
title = 'Pheno-Copter' | |
# task list for status of data processing | |
, dropdownMenuOutput('task_menu')) | |
# Side bar board | |
sidebar <- dashboardSidebar( | |
sidebarMenu( | |
id = 'menu_tabs' | |
, menuItem('menu1', tabName = 'menu1') | |
, menuSubItem('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 = 'image_viewer' | |
), | |
tabItem( | |
tabName = 'menu2' | |
, leafletOutput('map') | |
) | |
) | |
) | |
# 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') | |
}) | |
observe({ | |
input$mydata | |
proxy <- leafletProxy('map') | |
proxy %>% | |
setView(runif(1) * 10, runif(1) * 10, 7) | |
}) | |
} | |
shinyApp(ui, server) | |
This file contains hidden or 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('menu2', tabName = 'menu2') | |
, menuItem('menu1', tabName = 'menu1') | |
) | |
) | |
# 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