How to display multiple pictures (png) that are stored locally on Shiny
up vote
1
down vote
favorite
I tried searching online a lot for a similar question but could not find one that helps with my case. I am very new to Shiny so I hope you all can help me out. Below is a form of the code I have. I am having some trouble pulling some images locally. In the UI you can see in the drop down menu I can select multiple counties and combo them with a reason. In my folder I have many png files titled in this generic format: "CountyX reasonY .png" (there is a space before the file extension).
What I want to do is be able to render multiple pictures in a grid so I can compare the combinations of counties and reason (i.e. see County2 reason1 and County1 reason3 and County2 reason3 and County4 reason2 in a 2x2 grid (or 3x4 if I have 12 etc)). To make it easier, I have uploaded some png files here for experimentation: PNG 1, PNG 2, PNG 3, PNG 4.
The output$plots I have tried only works for displaying one image.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderImage({
filename <- normalizePath(file.path("<local path name to png files>", paste(input$countyInput, " ", input$reasonInput, " .png", sep = "")))
list(src = filename)
}, deleteFile = FALSE)
}
shinyApp(ui = ui, server = server)
Thanks for all your help.
r image shiny
add a comment |
up vote
1
down vote
favorite
I tried searching online a lot for a similar question but could not find one that helps with my case. I am very new to Shiny so I hope you all can help me out. Below is a form of the code I have. I am having some trouble pulling some images locally. In the UI you can see in the drop down menu I can select multiple counties and combo them with a reason. In my folder I have many png files titled in this generic format: "CountyX reasonY .png" (there is a space before the file extension).
What I want to do is be able to render multiple pictures in a grid so I can compare the combinations of counties and reason (i.e. see County2 reason1 and County1 reason3 and County2 reason3 and County4 reason2 in a 2x2 grid (or 3x4 if I have 12 etc)). To make it easier, I have uploaded some png files here for experimentation: PNG 1, PNG 2, PNG 3, PNG 4.
The output$plots I have tried only works for displaying one image.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderImage({
filename <- normalizePath(file.path("<local path name to png files>", paste(input$countyInput, " ", input$reasonInput, " .png", sep = "")))
list(src = filename)
}, deleteFile = FALSE)
}
shinyApp(ui = ui, server = server)
Thanks for all your help.
r image shiny
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I tried searching online a lot for a similar question but could not find one that helps with my case. I am very new to Shiny so I hope you all can help me out. Below is a form of the code I have. I am having some trouble pulling some images locally. In the UI you can see in the drop down menu I can select multiple counties and combo them with a reason. In my folder I have many png files titled in this generic format: "CountyX reasonY .png" (there is a space before the file extension).
What I want to do is be able to render multiple pictures in a grid so I can compare the combinations of counties and reason (i.e. see County2 reason1 and County1 reason3 and County2 reason3 and County4 reason2 in a 2x2 grid (or 3x4 if I have 12 etc)). To make it easier, I have uploaded some png files here for experimentation: PNG 1, PNG 2, PNG 3, PNG 4.
The output$plots I have tried only works for displaying one image.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderImage({
filename <- normalizePath(file.path("<local path name to png files>", paste(input$countyInput, " ", input$reasonInput, " .png", sep = "")))
list(src = filename)
}, deleteFile = FALSE)
}
shinyApp(ui = ui, server = server)
Thanks for all your help.
r image shiny
I tried searching online a lot for a similar question but could not find one that helps with my case. I am very new to Shiny so I hope you all can help me out. Below is a form of the code I have. I am having some trouble pulling some images locally. In the UI you can see in the drop down menu I can select multiple counties and combo them with a reason. In my folder I have many png files titled in this generic format: "CountyX reasonY .png" (there is a space before the file extension).
What I want to do is be able to render multiple pictures in a grid so I can compare the combinations of counties and reason (i.e. see County2 reason1 and County1 reason3 and County2 reason3 and County4 reason2 in a 2x2 grid (or 3x4 if I have 12 etc)). To make it easier, I have uploaded some png files here for experimentation: PNG 1, PNG 2, PNG 3, PNG 4.
The output$plots I have tried only works for displaying one image.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderImage({
filename <- normalizePath(file.path("<local path name to png files>", paste(input$countyInput, " ", input$reasonInput, " .png", sep = "")))
list(src = filename)
}, deleteFile = FALSE)
}
shinyApp(ui = ui, server = server)
Thanks for all your help.
r image shiny
r image shiny
edited Nov 20 at 5:27
asked Nov 20 at 5:22
kindofhungry
349
349
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
With grid
, gridExtra
and png
you can render the pngs into one "plot".
library(shiny)
library(shinyWidgets)
library(gridExtra)
library(png)
library(grid)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
filename <- normalizePath(file.path("<path>", paste0(input$countyInput, " ", input$reasonInput, ".png", sep = ""))) # you had one extra space before .png
pngs = lapply(filename, readPNG)
asGrobs = lapply(pngs, rasterGrob)
p <- grid.arrange(grobs=asGrobs, nrow = 1)
}, width = 1000)
}
shinyApp(ui = ui, server = server)
You will of course need some error handling for incomplete filenames. Also, you can use length(filename)
as a condition for nrow
and ncol
to get the wanted number of cells in the grid.
1
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
1
I addedwidth
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifyingnrow
s andwidth
– annhak
Nov 21 at 8:28
1
And FTR,width
will make the window scrollable, it won't cut the images.
– annhak
Nov 21 at 9:11
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
With grid
, gridExtra
and png
you can render the pngs into one "plot".
library(shiny)
library(shinyWidgets)
library(gridExtra)
library(png)
library(grid)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
filename <- normalizePath(file.path("<path>", paste0(input$countyInput, " ", input$reasonInput, ".png", sep = ""))) # you had one extra space before .png
pngs = lapply(filename, readPNG)
asGrobs = lapply(pngs, rasterGrob)
p <- grid.arrange(grobs=asGrobs, nrow = 1)
}, width = 1000)
}
shinyApp(ui = ui, server = server)
You will of course need some error handling for incomplete filenames. Also, you can use length(filename)
as a condition for nrow
and ncol
to get the wanted number of cells in the grid.
1
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
1
I addedwidth
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifyingnrow
s andwidth
– annhak
Nov 21 at 8:28
1
And FTR,width
will make the window scrollable, it won't cut the images.
– annhak
Nov 21 at 9:11
add a comment |
up vote
3
down vote
accepted
With grid
, gridExtra
and png
you can render the pngs into one "plot".
library(shiny)
library(shinyWidgets)
library(gridExtra)
library(png)
library(grid)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
filename <- normalizePath(file.path("<path>", paste0(input$countyInput, " ", input$reasonInput, ".png", sep = ""))) # you had one extra space before .png
pngs = lapply(filename, readPNG)
asGrobs = lapply(pngs, rasterGrob)
p <- grid.arrange(grobs=asGrobs, nrow = 1)
}, width = 1000)
}
shinyApp(ui = ui, server = server)
You will of course need some error handling for incomplete filenames. Also, you can use length(filename)
as a condition for nrow
and ncol
to get the wanted number of cells in the grid.
1
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
1
I addedwidth
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifyingnrow
s andwidth
– annhak
Nov 21 at 8:28
1
And FTR,width
will make the window scrollable, it won't cut the images.
– annhak
Nov 21 at 9:11
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
With grid
, gridExtra
and png
you can render the pngs into one "plot".
library(shiny)
library(shinyWidgets)
library(gridExtra)
library(png)
library(grid)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
filename <- normalizePath(file.path("<path>", paste0(input$countyInput, " ", input$reasonInput, ".png", sep = ""))) # you had one extra space before .png
pngs = lapply(filename, readPNG)
asGrobs = lapply(pngs, rasterGrob)
p <- grid.arrange(grobs=asGrobs, nrow = 1)
}, width = 1000)
}
shinyApp(ui = ui, server = server)
You will of course need some error handling for incomplete filenames. Also, you can use length(filename)
as a condition for nrow
and ncol
to get the wanted number of cells in the grid.
With grid
, gridExtra
and png
you can render the pngs into one "plot".
library(shiny)
library(shinyWidgets)
library(gridExtra)
library(png)
library(grid)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
filename <- normalizePath(file.path("<path>", paste0(input$countyInput, " ", input$reasonInput, ".png", sep = ""))) # you had one extra space before .png
pngs = lapply(filename, readPNG)
asGrobs = lapply(pngs, rasterGrob)
p <- grid.arrange(grobs=asGrobs, nrow = 1)
}, width = 1000)
}
shinyApp(ui = ui, server = server)
You will of course need some error handling for incomplete filenames. Also, you can use length(filename)
as a condition for nrow
and ncol
to get the wanted number of cells in the grid.
edited Nov 21 at 8:26
answered Nov 20 at 10:41
annhak
1816
1816
1
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
1
I addedwidth
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifyingnrow
s andwidth
– annhak
Nov 21 at 8:28
1
And FTR,width
will make the window scrollable, it won't cut the images.
– annhak
Nov 21 at 9:11
add a comment |
1
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
1
I addedwidth
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifyingnrow
s andwidth
– annhak
Nov 21 at 8:28
1
And FTR,width
will make the window scrollable, it won't cut the images.
– annhak
Nov 21 at 9:11
1
1
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
This really helped! Thanks for teaching me about the pngs package. I also learned about the differences between paste0 and paste. Very thankful for your help! P.S. My pngs have an intentional extra space before .png
– kindofhungry
Nov 21 at 7:10
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
Do you have any idea how to resize the images? My images are showing up smaller and it's hard to read. Also will making the images bigger make the window scrollable or cut it off?
– kindofhungry
Nov 21 at 7:17
1
1
I added
width
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifying nrow
s and width
– annhak
Nov 21 at 8:28
I added
width
to my answer. As shiny.rstudio.com/reference/shiny/0.14/renderPlot.html tells, you can use reactive values to specify the width. So maybe make a reactive expression for the number of images, and use that when specifying nrow
s and width
– annhak
Nov 21 at 8:28
1
1
And FTR,
width
will make the window scrollable, it won't cut the images.– annhak
Nov 21 at 9:11
And FTR,
width
will make the window scrollable, it won't cut the images.– annhak
Nov 21 at 9:11
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386688%2fhow-to-display-multiple-pictures-png-that-are-stored-locally-on-shiny%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown