无法将我的功能性 shiy 应用程序转换为具有闪亮模块的应用程序

德里克·科科伦

目前有效的方法

您好,我正在尝试为物种采样构建一个闪亮的应用程序。对于选择的每个物种,我需要选择哪种采样,如果它是在精确采样中选择的,则需要对其进行计数,这是一个工作示例:

library(shiny)
library(shinyMobile)

ui = f7Page(
  title = "Show navbar",
  f7SingleLayout(
    navbar = f7Navbar("Hide/Show navbar"),
    f7Button(inputId = "toggle", "Toggle navbar", color = "red"),
    f7Text(inputId = "SpeciesName", label = "SpeciesName"),
    shinyMobile::f7Card(
      f7Flex(
        textOutput("SpeciesAgain"),
        uiOutput("Sampling_type_ui"),
        uiOutput("SpeciesCount")
      )
    )
  )
)
server = function(input, output, session) {
  
  output$SpeciesAgain <- renderText({input$SpeciesName})
  
  output$Sampling_type_ui <- renderUI({
    req(input$SpeciesName)
    f7Select(inputId = "Sampling_type", 
             label = "Sampling type", 
             choices = c("Pin-point", "5m circle", "15m circle"))
    
  })
  
  output$SpeciesCount <- renderUI({
    if (req(input$Sampling_type) == "Pin-point") {
      shinyMobile::f7Stepper(inputId = "Species1", label = "Species count", min = 1, max = 1000, step = 1, value = 1)
    }
  })
  
  observeEvent(input$toggle, {
    updateF7Navbar()
  })
}

shinyApp(ui, server)

这就像我想要的那样工作,它一直等到我写了一个物种名称,f7select才会出现,如果我选择Pin-point,我可以使用计数器来获取个体数量。

这不起作用

但是我需要在真实的应用程序中选择几个物种,这就是为什么我想把它变成一个闪亮的模块。这是我尝试过的:

library(shiny)
library(shinyMobile)

#Species <- "Nothofagus"

Species_UI <- function(id){
  f7Text(inputId = NS(id,"SpeciesName"), label = "SpeciesName")
  shinyMobile::f7Card(
    f7Flex(
      textOutput(NS(id, "SpeciesAgain")),
      uiOutput(NS(id, "Sampling_type_ui")),
      uiOutput(NS(id,"SpeciesCount"))
    )
  )
}

Species_Server <- function(id){
  moduleServer(id, function(input, output, session) {
    output$SpeciesAgain <- renderText({input$SpeciesName})
    
    output$Sampling_type_ui <- renderUI({
      req(input$SpeciesName)
      f7Select(inputId = "Sampling_type", 
               label = "Sampling type", 
               choices = c("Pin-point", "5m circle", "15m circle"))
      
    })
    
    output$SpeciesCount <- renderUI({
      if (req(input$Sampling_type) == "Pin-point") {
        shinyMobile::f7Stepper(inputId = "Species1", label = "Species count", min = 1, max = 1000, step = 1, value = 1)
      }
    })
  })
}

library(shiny)
library(shinyMobile)

ui = f7Page(
    title = "Show navbar",
    f7SingleLayout(
      navbar = f7Navbar("Hide/Show navbar"),
      f7Button(inputId = "toggle", "Toggle navbar", color = "red"),
      Species_UI("Species")
    )
  )
  server = function(input, output, session) {
    
    Species_Server("Species")
    
    observeEvent(input$toggle, {
      updateF7Navbar()
    })
  }

  shinyApp(ui, server)

现在,当我这样做时,模块中的 UI 不会出现在应用程序中,但我不知道出了什么问题。

额外的问题

在应用程序的最后一个选项中,我想替换f7Text我用来输入物种 a 的f7SmartSelect,其中物种名称的输入如下:

library(shiny)
library(shinyMobile)

ui = f7Page(
  title = "Show navbar",
  f7SingleLayout(
    navbar = f7Navbar("Hide/Show navbar"),
    f7Button(inputId = "toggle", "Toggle navbar", color = "red"),
    f7SmartSelect(inputId = "SpeciesName", label = "SpeciesName", 
                  choices = c("Species1", "Species2", "Species3", "Species4", "Species5"),
                  multiple = T, openIn = "popup"),
    shinyMobile::f7Card(
      f7Flex(
        textOutput("SpeciesAgain"),
        uiOutput("Sampling_type_ui"),
        uiOutput("SpeciesCount")
      )
    )
  )
)
server = function(input, output, session) {
  
  output$SpeciesAgain <- renderText({input$SpeciesName})
  
  output$Sampling_type_ui <- renderUI({
    req(input$SpeciesName)
    f7Select(inputId = "Sampling_type", 
             label = "Sampling type", 
             choices = c("Pin-point", "5m circle", "15m circle"))
    
  })
  
  output$SpeciesCount <- renderUI({
    if (req(input$Sampling_type) == "Pin-point") {
      shinyMobile::f7Stepper(inputId = "Species1", label = "Species count", min = 1, max = 1000, step = 1, value = 1)
    }
  })
  
  observeEvent(input$toggle, {
    updateF7Navbar()
  })
}

shinyApp(ui, server)

以便为每个物种重复该模块

欢迎任何帮助

布列陶夫

您的代码中有两个问题:

  • UI 模块应该返回 atagList()所以你需要使用
tagList(
    f7Text(inputId = NS(id,"SpeciesName"), label = "SpeciesName"),
    shinyMobile::f7Card(
      f7Flex(
        textOutput(NS(id, "SpeciesAgain")),
        uiOutput(NS(id, "Sampling_type_ui")),
        uiOutput(NS(id,"SpeciesCount"))
      )
    )
)
  • 当您在服务器中创建输入(例如您的f7Select())时,您仍然需要注意命名空间。server模块的一部分中,您需要使用session$ns(id-of-input). 这在 R Shiny模块文章的“在模块中使用 renderUI”部分中指定。在您的情况下,您应该使用:
f7Select(inputId = session$ns("Sampling_type"), 
               label = "Sampling type", 
               choices = c("Pin-point", "5m circle", "15m circle"))

小补充:通常,在模块的 UI 部分,最好先定义ns <- NS(id)然后使用ns(id-of-input). 同样,在模块的服务器部分,您可以定义ns <- session$ns.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将 Material UI 应用程序转换为移动设备并使其具有响应性

有一种简单的方法可以将我的Apple应用程序转换为android应用程序吗?

如何将我的应用程序转换为Android TV应用程序?

我如何将符号转换为颜色编码闪亮的应用程序

将模块从应用程序转换为功能部件后,到处都“无法解析R”

我可以使用 Electron JS 将我的网络应用程序转换为桌面应用程序吗

应用程序无法使用模块的模块

具有循环片段依赖性的模块化单活动Android应用程序

无法从 String 转换为 HashMap Spring Boot 应用程序

具有 facebook 登录功能的渐进式网络应用程序(反应应用程序)

Android Studio 2.2.2将我的应用程序模块作为库发布到具有Bintray存储库的jcenter

无法加载应用程序0(mountpoint ='')-具有uwsgi的烧瓶应用程序

具有本机iOS功能的混合应用程序

具有无限导航功能的Android应用程序

具有异步功能执行的PySide应用程序

具有实时通信功能的 Spring Boot 应用程序

具有$的Haskell部分功能应用程序

如何设置具有各种功能的 WPF 应用程序

使Java Swing应用程序具有持久性

我的应用程序具有局部变量eror

如何将我的 Symfony 4 应用程序从开发模式转换为生产模式?

将我的应用程序主题转换为棒棒糖

将我的Node应用程序转换为Docker / Kubernetes吗?

如何将我的谷歌工作表脚本转换为网络应用程序?

在闪亮的应用程序外部创建反应功能

在闪亮的应用程序中删除反应性表达

无法在未命名的模块加载器应用程序中将用户详细信息服务强制转换为用户

错误“无法加载 DLL 'vjsnativ':找不到指定的模块。” 将应用程序转换为 .NET 4.5 后

无法在我闪亮的应用程序中使用反应性元素