#install.packages("shinyTree")
library(shiny)
library(gdata)
library(plyr)
library(ggplot2)
library(shiny)
mydata1 = read.csv("C:\\Users\\BPO18\\Documents\\Book1.csv")
#mynewdata<-mydata1[order(mydata1$state), ]
#df<-data.frame(mydata1$state, mydata1$salesman, mydata1$total_sales)
#df
nestates<-unique(mydata1$state)
nestates
#combineddata = rbind(dt1,dt2)
#sorteddata<-combineddata[order(combineddata$state),]
#newsorteddata<-sorteddata[order(sorteddata$total_sales),]
#newsorteddata
ui <- fluidPage(
titlePanel("Report 1"),
fluidRow(
column(3,
checkboxGroupInput("checkGroup",
h3("States"),
choices = nestates,
selected = 1)),
column(3,
dateRangeInput("dates", h3("Date range"))),
#sidebarLayout(position = "right",
# sidebarPanel(
# selectInput("region", "Region:",
# choices=nestates)),
mainPanel(
plotOutput(outputId="salesplot")
)
)
)
sales<-data.frame(mydata1$total_sales)
unique(sales)
man<-data.frame(mydata1$salesman)
unique(man)
server <- function(input, output) {
output$salesPlot <- renderPlot({
x <- c(sales)
y <- c(man)
barplot(x,y, col=rgb(0.2,0.4,0.6,0.6), xlab="salesman", ylab="total_sales" )
})
}
shinyApp(ui = ui, server = server)
Can you please post a sample of your data set mydata1
or a toy data set that resembles it. Also take a look at creating a reprex
so that we can better help you.
Other than that, you are using mainPanel
in your ui
which is meant to go inside a sidebarLayout
, which you are not using. I would suggest either changing that to fluidRow
so it can go below the two inputs or putting it inside a column
call inside of the first fluidRow
so that it is next to the inputs.
Additionally, you are converting a vector to a dataframe with your as.data.frame()
functions and then converting them back to a vector in your renderPlot
call by putting them in c()
. Maybe this will help:
# sales<-data.frame(mydata1$total_sales)
# unique(sales)
# man<-data.frame(mydata1$salesman)
# unique(man)
server <- function(input, output) {
output$salesPlot <- renderPlot({
x <- unique(mydata1$total_sales)
y <- unique(mydata1$salesman)
barplot(x,y, col=rgb(0.2,0.4,0.6,0.6), xlab="salesman", ylab="total_sales" )
})
}
On a side note, it also looks like your labels are backward but I left them how you had them since I can't be sure without the data.
HTH
Hello sir. Thank you for helping me out. I need some more help . i made the
changes with respect to what you have mentioned. how do i plot graphs based
on what the user selects from the checkboxinput?
Rgeards
Smriti
states salesman totalsales
assam a 10
assam b 20
tripura c 50
meghalaya d 0
tripura c 40
assam f 29
this is how my sample data looks. i tried what you said, but no luck. my
code looks like this now.
library(shiny)
require(ggplot2)
salesdata<-read.csv("C:\\Users\\Smriti\\Documents\\sampledata.csv")
#updated<-salesdata[order(salesdata$state),]
stateinfo<-table(unique(salesdata$state))
salesinfo<-data.frame(unique(salesdata$salesman))
ui <- fluidPage(
titlePanel("Hello User"),
fluidRow(
column(3,
checkboxGroupInput("checkGroup",
h3("States"),
choices = stateinfo,
selected = 1)),
fluidRow(
column(3,
dateRangeInput("dates", h3("Date range"))),
fluidRow(
column(3,
selectInput("select", h3("Select a salesman"),
choices = salesinfo)
))
)))
server <- function(input, output) {
output$salesPlot <- renderPlot({
x <- unique(mydata1$total_sales)
y <- unique(mydata1$salesman)
barplot(x,y, col=rgb(0.2,0.4,0.6,0.6), xlab="salesman",
ylab="total_sales" )
})
}
# c_id <- reactive({
# shiny::validate(
# shiny::need(input$state, "Select a state!")
# )
# salesdata[salesdata$state == input$state, "ID"]
# })
Well I am not exactly sure how you want to integrate your inputs into your graph as your data does not have a state or date column and reducing a bar plot with multiple salesman to one doesn't seem like what you want.
In general you need to call the input value in your server code as input$<your_inputId>
. You should check out this tutorial on working with inputs and outputs in shiny
I am sorry, my data is a csv file with the columns state, salesman and
totalsales
Regards
SMRITI
And I will work through the tuitorial you have mentioned and get back to
you. Thank you so much for the assistance. I am trying to learn things on
my won and I am working on an r shiny project single handedly for someone.
Regards
SMRITI