Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bring data into Shiny on the same port

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

PawanRamaMali/shinypayload

Repository files navigation

CRAN statusR-CMD-checktest-coveragepkgdownLifecycle: experimentalLicense: MITGitHub starsGitHub issuesGitHub last commitDownloads

Bring datainto Shiny on the same port 🚀

Seamlessly integratePOST requests andquery parameters into your existing Shiny apps asreactive values. Zero configuration - works with your current UI on the same port.

✨ Key Features

  • 🔌Same-port integration - No need for separate servers or ports
  • 📡RESTful API endpoints - Accept POST requests alongside your Shiny UI
  • 🔄Reactive data streams - POST data automatically becomes reactive values
  • 🛡️Built-in authentication - Token-based security for your endpoints
  • 📱Multiple data formats - JSON, form data, query parameters
  • 🌐Cross-session sharing - Data shared across all connected clients
  • 🚦Production ready - Comprehensive testing and CRAN-quality code

🚀 Quick Start

Installation

# Install from CRANinstall.packages("shinypayload")# Install development version from GitHubremotes::install_github("PawanRamaMali/shinypayload")# For local developmentdevtools::load_all()

Basic Example

library(shiny)library(shinypayload)# Your regular UI - no changes needed!base_ui<- fluidPage(  titlePanel("🚀 shinypayload Demo"),    fluidRow(    column(6,      h4("📊 Live Data"),      verbatimTextOutput("live_data")    ),    column(6,      h4("🔗 URL Parameters"),      verbatimTextOutput("url_params")    )  ),    hr(),  h4("📡 POST Endpoint"),  verbatimTextOutput("endpoint_info"))# Wrap your UI to handle POST requestsui<- payload_ui(base_ui,path="/api/data",token= Sys.getenv("API_TOKEN","demo-token"))server<-function(input,output,session) {# Get URL parametersoutput$url_params<- renderPrint({params<- params_get(session)if (length(params)>0)paramselse"No URL parameters"  })# Show endpoint URLoutput$endpoint_info<- renderText({url<- payload_endpoint_url(session,"/api/data")    paste("Send POST requests to:",url,"?token=demo-token")  })# React to incoming POST datalive_data<- payload_last("/api/data",session,intervalMillis=200)output$live_data<- renderPrint({data<- live_data()if (is.null(data)) {"Waiting for data... 📡"    }else {list(timestamp=data$meta$timestamp,payload=data$payload,source=data$meta$remote_addr      )    }  })}# IMPORTANT: Use uiPattern = ".*" for POST routingshinyApp(ui,server,uiPattern=".*")

Send Data to Your App

# Send JSON datacurl -X POST"http://localhost:3838/api/data?token=demo-token"\\  -H"Content-Type: application/json"\\  -d'{"sensor": "temperature", "value": 23.5, "unit": "celsius"}'# Send form datacurl -X POST"http://localhost:3838/api/data?token=demo-token"\\  -d"name=sensor01&status=active&reading=42"# Response: {"ok": true}

📖 Documentation

Core Functions

FunctionPurposeExample
payload_ui()Wrap UI to handle POST requestspayload_ui(my_ui, "/api", "token")
payload_last()Get reactive with latest POST datadata <- payload_last("/api", session)
params_get()Extract URL query parametersparams <- params_get(session)
payload_endpoint_url()Get full endpoint URLurl <- payload_endpoint_url(session, "/api")

Authentication Methods

# Query parameter (recommended)POST/api/data?token=your-secret-token# HTTP HeadersPOST/api/dataX-Ingress-Token:your-secret-token# ORAuthorization:your-secret-token

Supported Content Types

  • application/json - Parsed withjsonlite::fromJSON()
  • application/x-www-form-urlencoded - Parsed withshiny::parseQueryString()
  • Fallback: Attempts JSON parsing, returns raw text if failed

💡 Use Cases

📊 Real-time Dashboards

  • IoT sensor data streaming
  • Live monitoring systems
  • Real-time analytics

🤖 API Integration

  • Webhook receivers
  • External service integration
  • Microservice communication

📱 Mobile/Web Apps

  • React/Vue.js → Shiny data flow
  • Progressive web apps
  • Cross-platform integration

🔄 ETL Pipelines

  • Data ingestion endpoints
  • Batch processing triggers
  • Workflow automation

📂 Complete Examples

Explore our comprehensive examples ininst/examples/:

Each example includes ready-to-run code and curl commands for testing.

🛡️ Security Best Practices

  1. Always use tokens in production

    ui<- payload_ui(base_ui,"/api", Sys.getenv("API_SECRET"))
  2. Validate and sanitize input data

    observeEvent(payload_last("/api",session), {data<- payload_last("/api",session)()if (!is.null(data)) {# Validate required fieldsif (is.null(data$payload$user_id))return()# Sanitize inputs before useclean_data<-DBI::dbQuoteString(pool,data$payload$message)  }})
  3. Use HTTPS in production

  4. Implement rate limiting if needed

  5. Monitor and log API usage

🔧 Advanced Configuration

Multiple Endpoints

# Handle different data types on different pathsui<- payload_ui(base_ui,"/sensors","sensor-token")server<-function(input,output,session) {# Different reactives for different endpointssensor_data<- payload_last("/sensors",session)user_data<- payload_last("/users",session)# Process accordingly...}

Custom Polling Intervals

# High-frequency updates (100ms)fast_data<- payload_last("/live",session,intervalMillis=100)# Low-frequency updates (5 seconds)slow_data<- payload_last("/batch",session,intervalMillis=5000)

🤝 Contributing

We welcome contributions! Please see ourContributing Guidelines for details.

Development Setup

# Clone and install dependenciesgitclonehttps://github.com/PawanRamaMali/shinypayload.gitcdshinypayload# Install in development modedevtools::load_all()# Run testsdevtools::test()# Check packagedevtools::check()

📊 Package Status

  • 132 tests with comprehensive coverage
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Multiple R versions supported (R ≥ 4.1)
  • CRAN ready - passes all checks
  • Production tested - used in real applications

📋 Requirements

  • R ≥ 4.1
  • shiny ≥ 1.7.4
  • jsonlite (any version)

📄 License

This project is licensed under theMIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built on the amazingShiny framework
  • Inspired by the need for seamless data integration in web applications
  • Thanks to the R community for feedback and contributions

📞 Support


Made with ❤️ for the R and Shiny community

⭐ Star this repo🍴 Fork it📢 Share it

About

Bring data into Shiny on the same port

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp