0
library(sf)
library(tmap)
library(shiny)
library(shinydashboard)
library(bs4Dash)
library(shinydashboardPlus)
library(tigris)
library(colourpicker)

wi_co <- counties(55, cb = TRUE) %>% # debug data
  st_transform(4326)

ca_co <- counties(06, cb = TRUE) %>% # debug data
  st_transform(4326)

ui <- dashboardPage(
    header = dashboardHeader(title = 'layrs'), # page header
    options = list(sidebarExpandOnHover = FALSE), # global page options
    controlbar = dashboardControlbar(
      fileInput('layer1', 'Choose Geospatial Data', # file upload in control bar
                multiple = FALSE,
                accept = c('.geojson', '.kml')),
      actionButton('add-layer', 'placeholder')), # work in progress -- not functonal
    sidebar = dashboardSidebar(
      colourInput('col', 'Fill Color', 'purple'), # fill color picker
      colourInput('bcol', 'Border Color', 'Black'), # border color picker
      sliderInput('alpha', 'Opacity', min = 0, max = 100, value = 100, step = 0.1), # opacity slide
      numericInput('lwd', 'Border Width', value = 1) # border width
    ),
    body = dashboardBody(
        tmapOutput("userMap", height = "700px") # map output perameters
    )
)
server <- function(input, output) {
  output$userMap <- renderTmap( # render the map
    req(input$layer1)
    tm_shape(shp = st_read(input$layer1[4])) + # reactivity for user inputs
      tm_polygons(col = input$col, border.col = input$bcol, alpha=((input$alpha)/100), lwd = input$lwd)
  )
}

shinyApp(ui = ui, server = server)

Above is the code for my shiny app. I want to add the req() function to my map render so it will not try to render the map until the user has uploaded data. According to the examples I've looked at in the documentation and beyond, this seems to be the correct syntax so I am unsure to why I am having trouble.

I've tried placing the function in various locations and just cant seem to figure it out. This code spits a syntax error for missing a comma (comma is not used in the documentation). If I do add the comma, the app loads but the screen is greyed out and the app doesn't work properly.

Thank you for any and all help and the time you've generously taken.

  • I think you need renderTmap({ }). You are missing the {}. You didn't provide data so not able to test if this is the only problem. – stomper May 04 '23 at 01:09

0 Answers0