Skip to content

Instantly share code, notes, and snippets.

@byzheng
Last active February 26, 2016 12:35
Show Gist options
  • Save byzheng/4dc969043439bf44217d to your computer and use it in GitHub Desktop.
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)
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)
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)
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