闪亮:获取所选收音机的按钮选择值

时间:2016-01-26 19:17:23

标签: r shiny

我试图在闪亮的脚本中获取所选的单选按钮。这不是那么简单,因为我在服务器部分创建了单选按钮。我不得不这样做,因为单选按钮的名称来自数据库。现在,我需要返回在服务器部分中选择的值。 这是我的代码:ui.R

ui <- bootstrapPage(
  tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
  leafletOutput("map", width = "100%", height = "100%"),
  absolutePanel(top = 10, right = 10,
    dateInput("date", h3("Choose a date:"), value = as.Date("2016-01-17")),
    uiOutput("choose_columns"),
    checkboxInput("legend", "Show legend", TRUE)
    )
  )

这里是server.R

server <- function(input, output, session) {
con <- dbConnect(MySQL(),
         user="root", password="",
         dbname="shiny", host="localhost")

    rs <- dbSendQuery(con, "SELECT * FROM file,date WHERE date.IdDate=file.dateId AND date.date=\"17-01-2016\"")
    data <- fetch(rs, n=-1)
    mylist=list()
    for(i in 1:dim(data)[1]){
    mylist<-append(mylist,setNames(list(data[i,3]),data[i,3]))
    }       

  # Check boxes
  output$choose_columns <- renderUI({

    # Get the data set with the appropriate name
    #dat <- get(input$date)
    #colnames <- names(dat)
    rs <- dbSendQuery(con, "SELECT * FROM file,date WHERE date.IdDate=file.dateId AND date.date=\"17-01-2016\"")
    data <- fetch(rs, n=-1)
    mylist=list()
    for(i in 1:dim(data)[1]){
    mylist<-append(mylist,setNames(list(data[i,3]),data[i,3]))
    }

    # Create the checkboxes and select them all by default
     radioButtons("radio", label = h3("Variable"),
        choices = mylist,selected = 1)
  })

0 个答案:

没有答案