【发布时间】:2017-09-04 17:41:21
【问题描述】:
我希望运行一段代码,而不是根据闪亮 UI 上选择的输入执行子集。
为此,我尝试了不同的方法,但没有成功:
我想在 UI 中做这样的事情:
ui = navbarPage(title = 'panel',
fluidPage(
fluidRow(
column(2,
selectInput('a', label = "choose",
choices = unique(df$a)),
sliderInput(
'b', label = 'choose range:',
min = 5, max = 8, value = c(6,7)),
actionButton('click','click')),
column(5,
tableOutput('table')))))
在服务器上类似这样的东西
server = function(input,output){
df= data.frame(a = c(1,2,3,4), b = c(5,6,7,8))
observeEvent(input$click,{
df_ = subset(df,
a == input$a &
b %in% input$b[1]:input$b[2])
})
input$table = renderDataTable({
df_
})
}
运行这段代码会把我带到这个错误:
shinyApp(ui, server)
Warning: Error in $<-.reactivevalues: Attempted to assign value to a read-
only reactivevalues object
Stack trace (innermost first):
47: $<-.reactivevalues
46: $<- [#11]
45: server [#11]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
Error in `$<-.reactivevalues`(`*tmp*`, "table", value = structure(function
(...) :
Attempted to assign value to a read-only reactivevalues object
我认为我错过了一些具有反应性价值的重要事物,但我迷失了,因为我是新人,但很闪亮。我尝试了一些响应式按钮的示例,例如 Rstudio 提供的按钮,但没有成功。
【问题讨论】: