ROHIT JHA ROHIT JHA - 1 year ago 74
R Question

How to remove first two column(Stock,SaleDate) from render table

render table image

hello i am new to this i am not able to remove first two columns from subdata1 while showing on render table output

//server.r

library(RJDBC)
library(dplyr)
library(shiny)
library(ggplot2)
library(scales)
library(shinydashboard)
library(plotly)

dsn_driver = ""
dsn_database = "" # e.g. "BLUDB"
dsn_hostname = "" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
dsn_port = "" # e.g. "50000"
dsn_protocol = "" # i.e. "TCPIP"
dsn_uid = "" # e.g. "dash104434"
dsn_pwd = ""
jcc = JDBC("");
jdbc_path = paste("jdbc:db2://", dsn_hostname, ":", dsn_port, "/", dsn_database, sep="");
conn = dbConnect(jcc, jdbc_path, user=dsn_uid, password=dsn_pwd)
query ="select monthname(retail_str_sales_master.sale_date) as MONTHNAME,SALE_DATE,count(retail_str_sales_master.tri_id) as TRIID, year(retail_str_sales_master.sale_date) as yr,round(sum (retail_Str_sales_master.grand_total),2) AS TOTAL from retail_store,retail_str_sales_master where retail_store.store_id = retail_Str_sales_master.store_id GROUP BY SALE_DATE";
query1=dbGetQuery(conn,query)
biz = data.frame(

Stock = query1$MONTHNAME,
SaleDate=query1$SALE_DATE,
Total = as.numeric(as.character(query1$TOTAL)),
NumberOfBills=query1$TRIID,
stringsAsFactors = FALSE

)



# connection with dash db
shinyServer(function(input, output) {
output$Box1 = renderUI(selectInput("sector","select a month",c(unique(biz$Stock),"pick one"),"pick one"))

subdata1 = reactive(biz[which(biz$Stock == input$sector),])


//here i am not able to remove first two columns as i showed

output$view = renderTable({
if(is.null(input$sector) ){return()
} else if (input$sector == "pick one"){return()

} else return(subdata1())//here it is showing all data but i want to remove first columns while showing
})



output$plot <- renderPlot({
if (is.null(input$sector)){return()
} else if(input$sector == "pick one") { return()
} else p <- ggplot(data=subdata1() ,aes(x =Sector, y = total, xend =Sector, yend =total,group=1))+ geom_histogram(stat = "identity",fill = "blue")+
geom_text(aes(label = total,y =total), position = position_dodge(1.0),
vjust = 0)
print(p + theme(axis.text.x =
element_text(size = 10,angle = 45,hjust = 1,vjust = 1))) })
output$plot1 <- renderPlot({
if (is.null(input$sector) ){return()
} else if(input$sector == "pick one") { return()
} else p1 <- ggplot(data = subdata1() ,aes(x=SaleDate,y=Total,group=1))+ geom_point(colour="black") +
geom_line(colour = "red") + geom_text(data = subdata1(), aes(label = Total),
position=position_jitter(width=1,height=0.8), size=3)+ scale_y_continuous(labels = scales::comma)
labs(x = "SaleDate",
y = "Total")
print(p1 + theme(axis.text.x =
element_text(size = 10,angle = 45,hjust = 1,vjust = 1))) })

output$plot2 <- renderPlot({
if (is.null(input$sector) ){return()
} else if(input$sector == "pick one") { return()
} else p1 <- ggplot(data=subdata1() ,aes(SaleDate,NumberOfBills,group=1))+ geom_point(colour="black") +
geom_line(colour = "red") + geom_text(data = subdata1(), aes(label =NumberOfBills),
position=position_jitter(width=1,height = 0.8), size=3)
labs(x = "SaleDate",
y = "Total_Number_Of_Bills_Per_Day")
print(p1 + theme(axis.text.x =
element_text(size = 10,angle = 45,hjust = 1,vjust = 1))) })


//ui.r
library(shiny)
library(ggplot2)
library(shinydashboard)
library(plotly)
dashboardPage(
dashboardHeader(title = "STORE ANALYTICS"),
dashboardSidebar(

sidebarMenu(
uiOutput("Box1"),
uiOutput("Box2")
)
),
dashboardBody(
fluidPage(


fluidRow(

box(
width = 20, status = "info", solidHeader = TRUE,
title = "Total value of store per day sales",
plotOutput('plot1',width = "100%",height="500")

),

box(
width = 20, status = "info", solidHeader = TRUE,
title = "Total Number of bills per day sales",
plotOutput('plot2')


),
box(
width = 8, status = "info", solidHeader = TRUE,
title = "STORE SALES PER MONTH ",
tableOutput("view")
)

)

)

)


)

Answer Source

Hi try the following perhaps? I just removed the first column as defined below:

output$view = renderTable({
  df <- subdata1() #define subdata
  df <- as.data.frame(df) #ensure dataframe
  df <- df[,-1] #remove first column
  if(is.null(input$sector) ){return()}
  else if (input$sector == "pick one"){return()}
  else return(df)
})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download