在Shinyapps计算

时间:2018-06-06 11:46:16

标签: r shiny

我想计算一些值并将值返回到我的闪亮应用程序:

ui <- fluidPage(
sidebarLayout(
sidebarPanel(numericInput(inputId = "ME",
               label = "Maternal effect:",
               min = -1,
               max = 1,
               value = 0.5),
  numericInput(inputId = "CE",
               label = "Child effect:",
               min = -1,
               max = 1,
               value = 0.5)
),
mainPanel(h3(textOutput("Power"))
)
)
)


server <- function(input, output) {
bzc <- sqrt(abs(input$CE)) * sign(input$CE)     
bzm <- sqrt(abs(input$ME)) * sign(input$ME) 
results <- bzc * bzm
  output$Power <- renderPrint({results  
})
}

shinyApp(ui = ui, server = server) 

这并不适合工作。有关如何在闪亮的应用程序中计算的任何提示?

1 个答案:

答案 0 :(得分:0)

出现错误消息,因为您有import csv from io import StringIO mystr = StringIO("""id, word, super_id 1 , cat, 2 2 , bird, Nan 3 , dog, 1 4, fox , 1""") # replace mystr with open('file.csv', 'r') with mystr as fin: reader = csv.reader(fin, skipinitialspace=True) next(reader) # ignore header row, or use headers = next(reader) to extract fin_d = {int(ide): word for ide, word, super_id in reader} d = {1: [2, 3, 4], 3: [1]} # map keys and values of d using fin_d res = {fin_d[k]: list(map(fin_d.get, v)) for k, v in d.items()} print(res) {'cat': ['bird', 'dog', 'fox '], 'dog': ['cat']} - input之外的对象 - 函数。如果您想计算要在多个图中重复使用的内容,请使用renderreactive - 函数。

对于所有其他情况,只需在observe内添加bzcbzmresult的代码 - 函数:

render