Reputation: 101
I am new to shiny, and may be asking basic question.
I have a dataset in local machine as of now, which has store numbers and the items it sells along with other data.
What I wish is an app that will select one store number, list all the items in that store, and then based on selection of the item show all data for that store and item.
Please find the code below
ui.R
library(shiny)
df<-read.csv("C:/Users/adey1/Office Projects/NGSC_Shiny/Ensembler App/Trial Started on 05-06-2015//example1.csv")
category<-unique(df$item_nbr)
store<-unique(df$store_nbr)
sidebarPanel(
selectInput(inputId = "Store",
label = "Store",
store),
uiOutput("items"),
mainPanel(textOutput('values'))
)
server.R
shinyServer(function(input, output) {
output$items<-renderUI({
item_list<-unique(df$item_nbr[which(df$store_nbr==input$Store)])
radioButtons("item1", "Select Item", item_list)
})
output$value<-renderTable(
subset(df,store_nbr==input$store & item_nbr==as.integer(input$item1))
)
})
Can you suggest what is wrong, and what needs to be done?
Upvotes: 1
Views: 1230
Reputation: 101
I found this changes on server side works:-
server.R
shinyServer(function(input, output) {
output$items<-renderUI({
item_list<-unique(df$item_nbr[which(df$store_nbr==input$Store)])
radioButtons("item1", "Select Item", item_list)
})
dataset=reactive({
y=which(df$store_nbr==input$Store & df$item_nbr==input$item1)
df1=as.data.frame(cbind(df$date[y],df$item_nbr[y],df$units[y],df$store_nbr[y]))
names(df1)=names(df)
df1
})
output$value<-renderTable(
dataset()
)
})
But this is very crude. Can someone get me easier solution?
Upvotes: 1