I am new to shiny R. Trying to build a shopping webapp.
If we select a product "Apple" from mobiles, it should display product image and if we click that image it should take us to other/link page.
Kindly help me on this.
Below is my code.
library(shiny)
library(shinydashboard)
library(readr)
library(shinyalert)
library(htmltools)
trend_data <- read_csv("data/trend_data.csv")
####################################### Header #############################
header <- dashboardHeader(
title = span(
"SHOPKART ",
style = "font-family: Tahoma; font-weight: bold"
),
titleWidth = "350px",
dropdownMenu(type = "tasks",
messageItem(
from = "Cart",
message = "Want to add more?",
icon = icon("cart-plus")
)),
dropdownMenu(type = "messages",
messageItem(
from = "Offer",
message = "50% off on clothing",
icon = icon("hand-point-right")
))
)
####################################### Search #############################
sidebar <- dashboardSidebar(
useShinyalert(),
width = "350px",
sidebarMenu(
sidebarSearchForm(
textId = "search_text",
buttonId = "search_button",
label = "What are you looking for?",
),
####################################### Mobiles #############################
selectInput(
inputId = "mobiles", width = "350px",
label = "Mobiles:",
choices = unique(trend_data$type),
),
####################################### Clothing #############################
menuItem(
text = span("Clothing", style = "font-size: 17px"),
tabName = "cloth",
icon = icon("tshirt"),
menuSubItem(text = "Women", tabName = "women"),
menuSubItem(text = "Men", tabName = "male"),
menuSubItem(text = "Kids", tabName = "kid")
),
####################################### Electronics #############################
menuItem(
text = span("Electronics", style = "font-size: 17px"),
tabName = "elec",
icon = icon("tv"),
menuSubItem(text = "Laptops", tabName = "lap"),
menuSubItem(text = "Televisions", tabName = "Tel"),
menuSubItem(text = "Home Theatres", tabName = "sound")
),
####################################### Books #############################
menuItem(
text = span("Books", style = "font-size: 17px"),
tabName = "Book",
icon = icon("book-open"),
badgeLabel = "New",
badgeColor = "yellow"
),
br(),
br(),
br(),
hr(),
####################################### Signin #############################
menuItem(
text = span("Sigin/Register", style = "font-size: 17px"),
tabName = "sign",
icon = icon("user-plus"),
badgeLabel = "New User",
badgeColor = "blue"
),
####################################### About us #############################
menuItem(
text = span("About us", style = "font-size: 17px"),
tabName = "about",
icon = icon("question")
),
####################################### Contact us #############################
menuItem(
text = span("Contact us", style = "font-size: 17px"),
tabName = "contact",
icon = icon("headset")
)
)
)
####################################### Body #############################
body <- dashboardBody(
imageOutput("mob"),
)
####################################### Dashboard Page #############################
ui <- dashboardPage(
skin = "blue",
title = "dash",
header = header,
sidebar = sidebar,
body = body
)
####################################### Server #############################
server <- function(input, output, session) {
observeEvent(input$search_button, {
if(input$search_text != "")
shinyalert("Coming Soon", type = "warning")
}
)
output$mob <- renderImage({
if(input$mobiles == "Apple"){
return(list(
src = "www/iphone.jpg",
filetype = "image/jpg"
))}
else{
return(list(
src = "www/shop.jpg",
filetype = "image/jpg"
))
}
})
}
####################################### Session #############################
shinyApp(ui = ui, server = server)