Hi,
I am trying to display images ( loading image by url ) by selection . since there are more than 1 image per selection I would like to get help to create a dynamical html table / any other method to display images side by side Max 4 images per row.
how can I do that ??
Highlighted in yellow is the logic part that I am looking for,
Since
StateFlagImageurl will have more than 1 url I am not getting the logic... I know i have to use for loop but I am getting how to generate the table dynamically...
CSV Data :
Country
Here is the code that I am using ...
library(shiny)
data = read.csv("countrydata.csv")
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Test"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("Country", "Country",
choices = c("Enter a Country", data$Country))
),
# Show a plot of the generated distribution
mainPanel(
htmlOutput('image'),
htmlOutput('stateimage'
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output)
{
c_id <- reactive({
shiny::validate(
shiny::need(input$Country, "Select a Country!")
)
data[data$Country== input$Country, ]
})
getimage <- function(country){
c.info <- subset(data, Country==
country
,)
location <- toString(unique(c.info$CountryFlagImageurl))
return(location)
}
getstateimage <- function(state){
c.info <- subset(data, State== state
,)
location <- toString(c.info$StateFlagImageurl)
return(location)
}
output$image <-renderText({
paste0('<h2 align="center">Country Flag</h2><table width="100%"><tr align="center"><td width="33%">
<img src="',getimage(input$
CountryFlagImageurl
),'" border="10" alt="Link to this page">
</td></tr></table>')
})
output$stateimage <-renderText({
paste0('<h2 align="center">State Flag</h2><table width="100%"><tr align="center"><td width="33%">
<img src="',getstateimage(input$
StateFlagImageurl
),'" border="10" alt="Link to this page">
</td></tr></table>')
})
}