作者Tampa (光芒)
看板R_Language
標題[問題] shiny疑問
時間Tue Nov 29 21:43:41 2016
大家好 最近用shiny寫個小程式
上網找樣本然後自己來練習
想請問一下 shiny 是否有個類似開關的物件??
敘述如下
http://i.imgur.com/GmCCY5p.jpg
目前自己做的開關是用0/1來表示
現在想做的構想是,如果橫條選到0
則以下的清單都不可以動作
(畫面暗掉,不能動作,類似這樣的layout)
以下是我的程式碼
ui.r部分
library(shiny)
# Define UI for slider demo application
fluidPage(
# Application title
titlePanel("簡訊通知"),
# Sidebar with sliders that demonstrate various available
# options
sidebarLayout(
sidebarPanel(
# Simple integer interval
sliderInput("開關", "開關:",
min=0, max=1, value=1,step=1),
# Decimal interval with step value
sliderInput("發送時間", "發送時間:",
min = 8, max = 19, value = 1, step= 1,post=":00"),
# Specification of range within an interval
sliderInput("逾時", "逾時:",
min = 0, max = 23 , value = 1,step=1),
# Provide a custom currency format for value display,
# with basic animation
# Animation with custom interval (in ms) to control speed,
# plus looping
sliderInput("發訊時間", "發訊時間:",8, 19, 8,
step = 1, animate=
animationOptions(interval=1000, loop=TRUE))
),
# Show a table summarizing the values entered
mainPanel(
tableOutput("values")
)
)
)
sever.r部分
library(shiny)
# Define server logic for slider examples
function(input, output) {
# Reactive expression to compose a data frame containing all of
# the values
sliderValues <- reactive({
# Compose data frame
data.frame(
setting = c("開關",
"發送時間",
"逾時",
"發訊時間"),
Value = as.character(c(input$開關,
input$發送時間,
paste(input$逾時, collapse=' '),
input$發訊時間)),
stringsAsFactors=FALSE)
})
# Show the values using an HTML table
output$values <- renderTable({
sliderValues()
})
}
以上 感謝各位大大
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.240.249.32
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1480427024.A.769.html
推 yenyu0304: 可以用checkbox 來取代開關喔 11/29 22:14
推 yenyu0304: 在搭配uiOutput --有勾就看見下面U.i 沒勾就看不見 11/29 22:19
→ clansoda: 我沒看完你的code,但有這種conditional的需求 11/29 22:25
→ clansoda: 我建議你用conditionalpanel,在input$xxxx = 1的情況 11/29 22:25
→ clansoda: 他出現,input$xxxx = 0則消失,連點都不給點 11/29 22:26