1
library(shiny)
library(leaflet)
library(nycflights13)
library(DT)

parguera <- nycflights13::flights

r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()

ui <- fluidPage(
titlePanel("NOAA Caribbean Coral Data"),
leafletOutput("mymap"),
p(),
actionButton("laparguera", "La Parguera Data"),
actionButton("mona", "Mona Island Data"),
actionButton("isla", "Isla Catalina Data")
)

server <- function(input, output, session) {

output$mymap <- renderLeaflet({
leaflet() %>%
  addTiles() %>%
  addMarkers(lat = 17.95, lng = - 67.05, popup = "La Parguera ") %>%
  addMarkers(lat = 18.00, lng = -67.50, popup = "Mona Island") %>%
  addMarkers(lat = 18.2, lng = -69.00, popup = "Isla Catalina")
})
observeEvent(input$laparguera, {
DT::renderDataTable(DT::datatable(parguera)
 })
 }

shinyApp(ui, server)

Above is my code, trying to get the action button laparguera to display a dataframe. (Yes, I know it's plane data, not coral data, but I just want it to work first). Why is the action button not working?

madhatter5
  • 129
  • 2
  • 15
  • Does this code actually run for you? You seem to be missing a closing parenthesis for your `renderDataTable()` call. You should be getting a syntax error there. – MrFlick Apr 05 '17 at 21:01

1 Answers1

0

You call renderDataTable() but you never specify where it's supposed to go. YOu need a dataTableOutput() object in your UI. Something like

ui <- fluidPage(
  titlePanel("NOAA Caribbean Coral Data"),
  leafletOutput("mymap"),
  p(),
  actionButton("laparguera", "La Parguera Data"),
  actionButton("mona", "Mona Island Data"),
  actionButton("isla", "Isla Catalina Data"),
  DT::dataTableOutput('tbl')
)

Then you should have

observeEvent(input$laparguera, {
    output$tbl <- DT::renderDataTable(DT::datatable(parguera))
})

in your server() function.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • And yes, I left out one superfluous bit because it wouldn't transfer over to here well, and forgot the parenthesis. – madhatter5 Apr 05 '17 at 21:25