昨天我问了这个问题(Update two sets of radiobuttons reactively - shiny),但也许这太乱了,无法得到回复。我已经剥离下来的问题:为什么我不能得到两套单选按钮来被动更新:更新两套单选按钮 - 闪亮
server.R:
# Create example data
Wafer <- rep(c(1:3), each=3)
Length <- c(1,1,2,1,1,1,3,5,1)
Width <- c(3,1,6,1,1,1,1,1,6)
dd <- data.frame(Wafer, Length, Width)
shinyServer(function(input, output, session){
# Get Lengths from user input
a <- eventReactive(input$do, {
subset(dd, Wafer %in% input$wafer, select = Length)
})
# Get Widths from user input
b <- eventReactive(input$do, {
subset(dd, Wafer %in% input$wafer, select = Width)
})
#Observe and update first set of radiobuttons based on a(). Does
#render
observe({
z <- a()
updateRadioButtons(session, "length", choices = unique(z$Length), inline=TRUE)
})
#Observe and update second set of radiobuttons based on b(). Does
#not render
observe({
z <- b()
updateRadioButtons(session, "width", choices = unique(z$Width), inline=TRUE)
})
output$l <- renderDataTable({ a() })
output$w <- renderDataTable({ b() })
})
ui.R:
library(markdown)
shinyUI(fluidPage(
titlePanel("Generic grapher"),
sidebarLayout(
sidebarPanel(
numericInput("wafer", label = h3("Input wafer ID:"), value = NULL),
actionButton("do", "Search wafer"),
radioButtons("length", label="Length", choices=""),
radioButtons("width", label="Width", choices = "")
),
mainPanel(
dataTableOutput(outputId="l"),
dataTableOutput(outputId="w")
)))
)
在上面,我只能得到一组单选按钮来响应(“长度”)。但是,如果我注释出长度为observe
,那么宽度就会起作用,所以我的代码必须单独运行。也许我错过了一些简单的东西?
好吧,所以如果我改变一组单选按钮是一个selectInput并将相应的updateRadioButtons更改为updateSelectInput,那么它就可以工作。我可以使用它,但如果任何人都可以指向正确的方向,我宁愿选择两组单选按钮。 – Pete900
可能是一个错误,我改变了'updateRadioButtons'的顺序,只有第一个工作... – NicE
谢谢尼克。有什么我可以做的吗?也许是RStudio页面或Git的东西?我从来没有做过这样的事情,所以不知道正确的礼节。 – Pete900