library(RODBC)
library(RODBCext)
#>
#> Attaching package: 'RODBCext'
#> The following objects are masked from 'package:RODBC':
#>
#> odbcFetchRows, sqlFetchMore
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
library(shiny)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
library(tidyr)
dbcnd <- odbcDriverConnect('Driver={SQL Server};Server=;Database=;Uid=;Pwd=')
rm(list=ls())
ui <-fluidPage(
titlePanel("Reactive select input boxes"),
sidebarPanel(
uiOutput("FirstChoice"),
uiOutput("SecondChoice")
),
mainPanel()
)
server = function(input, output) {
dbcnd <- odbcDriverConnect('Driver={SQL Server};Server=;Database=;Uid=sa;Pwd=')
qrydd<-paste("exec database_name[sp_name]'','','','','0','0','0','','','01/01/2010','31/12/2019'")
qrydd
dtd <- sqlQuery(dbcnd,qrydd)
dtd <- data.frame(dtd)
dtd
closeAllConnections()
qrydd1<-paste("exec database_name[sp_name]'','','','','0','0','2','0','','01/01/2017','31/12/2017'")
qrydd1
dtd1 <- sqlQuery(dbcnd,qrydd1)
dtd1 <- data.frame(dtd1)
dtd1
closeAllConnections()
countyData = data.frame("Raj"=c(dtd$DistrictName),"State"=c(dtd1$StateName),stringsAsFactors = FALSE)
output$FirstChoice <- renderUI ({
selectInput(inputId = "FirstChoice",label = "Raj/State",
choices = c("Raj","State"))
})
output$SecondChoice <- renderUI ({
sub <- select(countyData, input$FirstChoice)
if (input$FirstChoice == "Raj"){lab <- "Raj"}
else if (input$FirstChoice == "State") {lab <- "State"}
else {lab <- "dependant"}
selectInput(inputId = "SecondChoice", label = lab,
choices = c(get(input$FirstChoice,sub)))
})
}
shinyApp(ui = ui, server = server)
StackOverflow link for the same question
countyData = data.frame("Raj"=c(dtd$DistrictName),"State"=c(dtd1$StateName),stringsAsFactors = FALSE)
throwing an error different number of rows bcoz query1 contains 34 records and query2 contains 33 records,
*does anyone know how to get it right and even though *
i use the same stored procedure(just for testing) to avoid this,
why is this giving numbers like(1,2,3 till 34) in sub-menu instead of names of the 34 district.
could anyone please guide me through what I am doing wrong here.
let's say....
inputvalue<-data.frame(a=c("Ajmer","Alwar","Banswara","Baran","Barmer"),
b=c("Chittorgarh","Churu","Dausa","Dholpur","Dungarpur"))
countyData =data.frame("Raj"= c(inputvalue$a),
"State"=c(inputvalue$b),stringsAsFactors = FALSE)
and why this prints number instead of real vector values like "Ajmer","Alwar","Banswara"
and so on .how to convert this ino a string format