0

I'm new to R and shiny package.

I have created a map with tmap and gdal packages and I woud like to know how to display it in a shiny tab ?

Which is the command that allows it ?

Thank you very much.

Have a great day.

Ok, so, this is what I did with maptools package, but there's nothing in the tab :

    server : shpFile <- readShapePoly("c:\shapefiles\counties.shp")
             output$map <- renderPlot({shpFile})


    ui : tabPanel("Map",
                         mainPanel(plotOutput("map"))
                                   )

So, if you see where is the problem, thank you for helping me.

EDIT : Ok, I found it.

This is the Server.R code :

output$SHPplot <-  renderPlot({
  lnd <- readOGR(dsn = "//test/Shapefiles",
                 layer = "Countries")

tm_shape(lnd) +
    tm_fill("COUNTRIES", title = "GDP", style = "fixed",
            breaks = c(60, 70, 80, 90, 100),
            #      palette = c("red", "yellow", "blue", "turquoise")) +
            #      col=c("#edf8fb", "#b2e2e2", "#662a4", "238b45")) +
            palette = "YlOrRd") +
    tm_borders() +
    tm_layout("Wealth (or so)",
              legend.title.size = 1,
              legend.text.size = 0.6,
              legend.position = c("left","bottom"),
              legend.bg.color = "white",
              #legend.digits = 5,
              legend.bg.alpha = 1)
      })

And Ui.R code :

plotOutput("SHPplot", height = 675)

Thanks for helping.

Mickey_NC
  • 269
  • 1
  • 5
  • 17
  • 2
    Can you display other things in shiny tabs? Where exactly are you getting stuck? It would be better if you could provide some sort of minimal [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to show us where the problem is. – MrFlick Oct 11 '16 at 20:48
  • look at ?renderPlot – HubertL Oct 11 '16 at 20:48
  • 1
    Yes please provide what you have already tried? Is the standard function "renderplot" not working for you? – Rohit Das Oct 11 '16 at 20:49

1 Answers1

2

Shiny works with two main elements: server.R and ui.R. If you want to display a map, you could use this structure:

server.R

output$plot_map <- renderPlot({

  • put the function which makes your map here *

})

ui.R

plotOutput("plot_map")

F. Requena
  • 51
  • 1
  • 4
  • Here is an example function `library(tmap)`, then inside `renderPlot`, `data(Europe)`, `qtm(Europe)`. – Xiongbing Jin Oct 11 '16 at 21:21
  • Thank you for all your answers. @ MfFlick and Rohit Das, sorry, I have no code to provide because as I'm a beginner, I just ignore how to render a map in shiny. At this moment, I just created an UI with 4 tab panels displaying data frames. And I just created a map with tmap and rgdal packages, but it is displayed in the viewer window of R studio and I don't know how to insert it in the UI. @ F. Requena, do you think renderPlot is able to work with qtm tmap instruction ? Because it imports a shapefile. Anyway, thank you again. – Mickey_NC Oct 11 '16 at 22:23
  • Ok this what I did but it displays nothing : – Mickey_NC Oct 12 '16 at 04:59